-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Closed
Labels
Description
The Set-Cookie
header is special, it is not correct to combine multiple Set-Cookie
headers into a single value separated by commas because it can change the semantics.
Reference:
- whatwg fetch, "Headers class": https://fetch.spec.whatwg.org/#headers-class (see the note directly below the structure definition of
Headers
) - RFC6265 section 3: https://tools.ietf.org/html/rfc6265#section-3
I think the only correct way to parse this header with node-fetch
is by using raw()
. This is not at all obvious and should probably be documented.
Some (untested!) example code:
if (cookieJar && res.headers.has('Set-Cookie')) {
for (const [k, vv] of Object.entries(res.headers.raw())) {
if (k.toLowerCase() === 'set-cookie') {
for (const v of vv) {
await promisify(cookieJar.setCookie)(v, url);
}
}
}
}
Noitidart