In one of the projects I started to work on the original owner uses node-fetch for http request. node-fetch provides res.headers.get('set-cookie') but it only returns one of the set-cookie headers. (Usually you can have multiple set-cookie in a response header).
Without abandoning node-fetch, is it possible to get all set-cookie headers from the response?
res.headers.raw() returns a map of header names to arrays of header values; so something like:
res.headers.raw()['set-cookie'].each(c => console.log(c))
Will do the trick, I believe.
The Headers object has a get method that returns an Array.
You must be using an older version of node-fetch. In 2.x, res.headers.get should be compliant with the spec.
res.headers.get('set-cookie'); // Array
If you can't upgrade to 2.x for some reason, you can use the non-standard getAll method instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With