question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't remove default headers. Can't overwrite `"sec-fetch-mode"`, `"connection"` headers.

See original GitHub issue
  • I can’t remove any default header.
  • Setting "connection": "keep-alive" throws an error.
  • I can’t overwrite default "sec-fetch-mode" header correctly.

1. I can’t remove the default headers

I can’t remove the default headers: host, connection, accept, accept-encoding, accept-language, sec-fetch-mode, user-agent.

For example, curl allows to remove any header (even host header): curl http://127.0.0.1:3000 -H 'User-Agent:' -H 'Accept:' -H 'Host:' And yes, it works.

Using of "" will send "" as the header’s value, using of null will send "null" as the header’s value.

2. "connection": "keep-alive"

Also, if I manually set connection: "keep-alive" I get the error (code: 'UND_ERR_INVALID_ARG').

const resp = await fetch(url, {
    headers: {
        "connection": "keep-alive"
    }
});

It’s important for code compatibility reason — since node-fetch uses connection: close by default.

3. "sec-fetch-mode"

It uses "sec-fetch-mode": "cors" by default.

As I said above, I can’t remove this header (as well as any other default header).

More over, I can’t change it correctly.

For example, using of:

await fetch(url, {
    headers: {
        "sec-fetch-mode": "navigate"
    }
});

Will produce a request with sec-fetch-mode: navigate, cors, while it should be sec-fetch-mode: navigate.


"undici": "4.16.0"

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:1
  • Comments:25 (16 by maintainers)

github_iconTop GitHub Comments

5reactions
benjamingrcommented, Mar 28, 2022

So, I assume the next things will be implementing of CORS, CORB limitations, restricting of the access to “cookie” header since it’s a browser API? [sarcasm]

You know, there are people out there asking Node to do all these things (like CORS support) and some server runtimes like Deno with the concept of an origin are in fact implementing some of this stuff.

So this is not as out of the question as you may assume.


Also, please avoid sarcasm/snark in the tracker. We don’t know you well (yet) and it’s super easy to take things the wrong way in these situations without a lot of prior context (which we don’t have yet!) and it’s important to me that your contribution (feedback) on what node does here doesn’t get overlooked because of that.


That said I tend to agree node’s fetch should allow overriding these things unlike the browser’s. I also absolutely agree with Robert it’s not clear cut. I can ask in a forum of server runtimes I participate in but if you want to move this ahead it’d be great to do what server runtimes that implement fetch do (Deno/cloudflare/shopify etc) as well as what user-land implementations (like node-fetch) do.

5reactions
ronagcommented, Mar 28, 2022

undici is not a browser. Don’t overengineer it.

Easier said than done. Knowing what parts of the spec to ignore or not is not that easy. To keep things simple with the limited development time we have (I’m doing this work for free) it’s much easier to just follow the spec verbatim, i.e. the aim here is to match the browser as closely as possible and not bike-shed over what is right or wrong; the spec/Chrome is right (with few well discussed exceptions).

undici is not a browser. Don’t overengineer it.

fetch is a browser API. If you don’t want/need the browser behavior then don’t use the fetch API. We have much better API’s for node, e.g. undici.request.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I remove default headers that cURL sends?
Use -H flag with the header you want to remove and no content after the : -H, --header LINE Custom header to pass...
Read more >
Sec-Fetch-Mode - HTTP - MDN Web Docs
The Sec-Fetch-Mode fetch metadata request header indicates the mode of the request.
Read more >
Fetch Standard
To delete a header name name from a header list list , remove all headers whose name is a byte-case-insensitive match for name...
Read more >
PHP 5 ChangeLog
Fixed bug #72094 (Out of bounds heap read access in exif header processing). ... Fixed bug #66109 (Can't reset CURLOPT_CUSTOMREQUEST to default behaviour) ......
Read more >
(The only proper) PDO tutorial
Note that default mode is PDO::FETCH_BOTH , but you can change it using ... but, as this is a connection-only option and thus...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found