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.

Provide a way to access raw headers

See original GitHub issue

This 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:

  1. Node-fetch provides a non-standard Headers.prototype.raw method that returns entries for each (including duplicate) header.
  2. Re-introduce Headers.prototype.getAll to return multiple header values.

I have also considered…

  1. Not use undici primitives within NodeJS.
  2. Attempt to monkey patch undici

Additional context

  1. Cloudflare implemented .getAll().
  2. Node-fetch .raw() implementation
  3. Tracking at WinterCG

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:2
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
KhafraDevcommented, Jun 5, 2022

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.

1reaction
KhafraDevcommented, May 12, 2022

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').

Read more comments on GitHub >

github_iconTop 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 >

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