This is because the values of set-cookie headers can contain commas, such as in the case of a cookie with an expiry time (e.g. cookie-name=cookie-value; Path=/; Expires=Thu, 21 Sep 2023 06:12:39 GMT; Secure). Combining them with commas can change their semantics.
This library currently seems to ignore this part of the spec, and combine set-cookie values. For example, this is the current behaviour of whatwg-fetch:
For context, I'm using whatwg-fetch as a polyfill for running Jest tests that use Mock Service Worker (MSW), similar to this example over in the MSW project. I noticed this issue because I was setting multiple cookies with different options, and the combining of the cookie values was causing strange behaviour in my tests.
The Fetch Standard defines special behaviour for
Set-Cookie
headers:This is because the values of
set-cookie
headers can contain commas, such as in the case of a cookie with an expiry time (e.g.cookie-name=cookie-value; Path=/; Expires=Thu, 21 Sep 2023 06:12:39 GMT; Secure
). Combining them with commas can change their semantics.This library currently seems to ignore this part of the spec, and combine
set-cookie
values. For example, this is the current behaviour ofwhatwg-fetch
:In comparison, Chrome and Firefox follow the spec (Safari doesn't):
This seems to be a pretty recent addition to the spec (2021ish). There's also a new method Headers: getSetCookie() method added around the same time which is missing from
whatwg-fetch
:For context, I'm using
whatwg-fetch
as a polyfill for running Jest tests that use Mock Service Worker (MSW), similar to this example over in the MSW project. I noticed this issue because I was setting multiple cookies with different options, and the combining of the cookie values was causing strange behaviour in my tests.