Provide a way to access raw headers
See original GitHub issueThis would solve…
As outlined at WHATWG/fetch there is often the need in a server environment to access cookie headers.
For example editing Cookie headers:
const h = new Headers;
h.append("Set-Cookie", "a=1; Expires=Wed, 21 Oct 2015 07:28:00 GMT");
h.append("Set-Cookie", "b=1; Expires=Wed, 21 Oct 2015 07:28:00 GMT");
h.get("Set-Cookie")
// a=1; Expires=Wed, 21 Oct 2015 07:28:00 GMT, b=1; Expires=Wed, 21 Oct 2015 07:28:00 GMT
Splitting the combined header value by , will give an invalid result. Instead getAll could be used to retrieve the individual headers.
The implementation should look like…
There are two solutions currently proposed:
- Node-fetch provides a non-standard
Headers.prototype.raw
method that returns entries for each (including duplicate) header. - Re-introduce
Headers.prototype.getAll
to return multiple header values.
I have also considered…
- Not use undici primitives within NodeJS.
- Attempt to monkey patch undici
Additional context
- Cloudflare implemented .getAll().
- Node-fetch
.raw()
implementation - Tracking at WinterCG
Issue Analytics
- State:
- Created a year ago
- Reactions:2
- Comments:5 (3 by maintainers)
Top Results From Across the Web
How to view the whole raw http request? - Stack Overflow
In Chrome CTRL + SHIFT + C to launch Chrome Console. From there select Network Tab; There you can see the POST Request...
Read more >Get raw HTTP-Headers in Chrome (Example) - Coderwall
Get raw HTTP-Headers in Chrome · Open a new tab and enter about:net-internals as the URL · Go to Events tab · Enter...
Read more >How to view HTTP headers in Google Chrome? - Mkyong.com
In Chrome, visit a URL, right click , select Inspect to open the developer tools. · Select Network tab. · Reload the page,...
Read more >Access-Control-Request-Headers - HTTP - MDN Web Docs
The Access-Control-Request-Headers request header is used by browsers when issuing a preflight request to let the server know which HTTP ...
Read more >Node.js http.IncomingMessage.rawHeaders Method
Return Value: This method returns the raw request/response headers list exactly as they were received. Request List. Example 1: Filename: index.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Headers.prototype.getSetCookie
will solve this use case. I don’t think another solution would be accepted unless something is decided in the wintercg fetch group.Deno most likely does this just because it’s better for the user; otherwise the array of set-cookie headers wouldn’t be exposed.
The current headers implementation would need an overhaul to support this. It stores headers as strings, rather than arrays (which I believe goes against the spec) and doesn’t concat values when using
.get()
(as, well, they’re already strings).I can see adding
.getAll()
, and like cloudflare, making it only work on set-cookie headers.edit: Unlike a header list, a Headers object cannot represent more than one Set-Cookie header. In a way this is problematic as unlike all other headers Set-Cookie headers cannot be combined, but since Set-Cookie headers are not exposed to client-side JavaScript this is deemed an acceptable compromise. Implementations could choose the more efficient Headers object representation even for a header list, as long as they also support an associated data structure for Set-Cookie headers.
It looks like undici only needs to store
set-cookie
headers as arrays and instead allowing.getAll('set-cookie')
.