[Response Headers]: set multiple headers of same key in response
See original GitHub issueI’ve a node-proxy server using node-fetch to get the data from server. The server responds with multiple set-cookie
header. I want to add this to the response to the client.
I first parsed using res.headers.raw()['set-cookie']
this gives me array of cookies but now I want to set it in response and I tried using set
, append
both of these methods just set the value in one header set-cookie
separated by comma. Is there any way to have multiple set-cookie
headers in response?
set-cookie: cookie1=value1
set-cookie: cookie2=value2
Issue Analytics
- State:
- Created 3 years ago
- Reactions:6
- Comments:11 (3 by maintainers)
Top Results From Across the Web
Setting multiple response headers with same name, different ...
It MUST be possible to combine the multiple header fields into one "field-name: field-value" pair, without changing the semantics of the message ...
Read more >How to add multiple Headers with the same name containing ...
The slice elements represent different values for the header named by the map key. Use Header.Add to add multiple values for a given...
Read more >Multiple header values with the same name - HTTPie
If the request is sent with multiple headers that are sharing the same name, then the HTTPie will send them individually. It is...
Read more >Access multi-value HTTP headers incorrectly in an API Proxy ...
Accessing the values of HTTP headers in Apigee policies in a way that returns only the first value is incorrect and can cause...
Read more >HTTP headers - MDN Web Docs - Mozilla
HTTP headers let the client and the server pass additional information with an HTTP request or response. An HTTP header consists of its ......
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 FreeTop 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
Top GitHub Comments
I want to highlight what @smolnikov said above – RFC 6265 says one SHOULD NOT do this for
Set-Cookie
specifically (and RFC 7230 echoes this as a special case). It’s acceptable for other headers, just notSet-Cookie
. The browserfetch
doesn’t need to care because it doesn’t let you seeSet-Cookie
at all.That said, for anyone else reading this thread, it’s easy enough to work around by using
headers.raw()['Set-Cookie']
, which will give you a proper array of set-cookie values. (Except actually it’s a little more complicated than that, because you need to use the capitalization to match whatever the first time a set-cookie was added to this header. You can find this by iterating overheaders.keys()
, then using thatname
.) That’s what we’re doing.Looks like this is how standard is defined, try this in the browser console and you will get the stringified result too:
node-fetch is mostly about following the specs
What’s interesting is that documentation on MDN is wrong and suggests an array being returned when appending another header: https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch
But you can test yourself that’s not valid.
How to get around this? I have no idea. As you are controlling the response and not what’s reading it no “workaround” with splitting string is good here.
Probably using something else, more raw that is not following the Response/Headers standard is the only way to go.