-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to set multiple "set-cookie" headers #29
Comments
Hey, @aleehedl. Thanks for raising this. Just as with the native If you wish to set multiple headers, use const { Headers } = require("headers-polyfill")
let h = new Headers()
h.append('set-cookie', 'foo=bar')
h.append('set-cookie', 'bar=baz')
h.get('set-cookie') // "foo=bar, bar=baz" This is the same behavior as the native |
Thanks for the response @kettanaito. The comma-separated value isn't usable with cookies, because browsers don't accept multiple cookies in a single
|
I don't think the issue you're describing is directly related to the let h = new Headers()
h.append('Set-Cookie', 'foo=bar')
h.append('Set-Cookie', 'bar=baz')
h.get('Set-Cookie') I may not understand the issue fully here. Could you please elaborate more on what exactly you're trying to do, in what context, etc.? If a reproduction repository or a sandbox can help you share that info, please create that. |
Here's a simple repo: There are two servers you can start: And a possbily running codesandbox: The main thing is: Browser doesn't set two cookies when the values come in a single Set-Cookie header. |
Thank you for preparing those! So it seems like an issue with how MSW handles cookies, not the
About that. In the browser, you cannot set const res = new Response(null, { headers: { 'Set-Cookie': 'foo=bar, bar=baz' } })
res.headers.get('Set-Cookie') To account for that, MSW reads your mocked cookies and forwards them onto the |
1 similar comment
Thank you for preparing those! So it seems like an issue with how MSW handles cookies, not the
About that. In the browser, you cannot set const res = new Response(null, { headers: { 'Set-Cookie': 'foo=bar, bar=baz' } })
res.headers.get('Set-Cookie') To account for that, MSW reads your mocked cookies and forwards them onto the |
Oh, I see what may be off. In MSW, the I will create an issue in the MSW repository where we can follow up. |
Opened in mswjs/msw#1290. |
https://developer.mozilla.org/en-US/docs/Web/API/Headers/getSetCookie This function may help solve this problem. |
Thanks for the suggestion, @gucong3000. However, it's also mentioned the first thing in the Examples that You can use the |
@kettanaito Thanks for your work. I'm using this package under node.js. Great work. |
Thanks for your kind words! Yeah, Headers can be used to declare any headers. In the context of this issue, accessing the response headers was a pre-requisite so I discussed it respectively. |
According to MDN, setting multiple cookies in an HTTP response should be done by using multiple "Set-Cookie" headers.
As far as I know, this is not possible with the headers-polyfill.
There should be a way for setting multiple
set-cookie
entries. Comma-separated value (set-cookie: foo=bar, bar=baz
) is deprecated and not implemented by modern browsers.The text was updated successfully, but these errors were encountered: