You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since Node.js 17.5, we can pass --experimental-fetch to use the built-in undicifetch implementation.
Sadly even if fetch-cookie now theoretically supports WHATWG fetch standard (through response.headers.get('set-cookie') and splitCookieString), undici in most cases drop the set-cookie header, most likely because the spec says it's a forbidden header, and fetch-cookie cannot work with it.
As pointed out by @justingrant in whatwg/fetch#1384 (comment) (I'm following up here because this discussion is off topic for the linked issue), undici do expose the set-cookie header in some cases.
I confirmed on Node 17.5 and I am able to read the Set-Cookie header:
(awaitfetch('https://wikipedia.com/')).headers.get('set-cookie')'WMF-Last-Access=26-Feb-2022;Path=/;HttpOnly;secure;Expires=Wed, 30 Mar 2022 12:00:00 GMT, WMF-Last-Access-Global=26-Feb-2022;Path=/;Domain=.wikipedia.org;HttpOnly;secure;Expires=Wed, 30 Mar 2022 12:00:00 GMT, GeoIP=...; Path=/; secure; Domain=.wikipedia.org'
That's a good news but from my testing, the set-cookie header is not always returned. It seem to be related to responseTainting and the CORS implementation of undici but I couldn't figure precisely in what conditions undici will or will not drop the set-cookie header.
Typically in the earlier URL https://wikipedia.com/, it issues a redirect to https://www.wikipedia.org/ which is the actual response setting the cookie, as shown by:
And the same goes for every request I've done with redirect: 'manual', which is a requirement for fetch-cookie to do its job.
I'd love fetch-cookie to eventually work with the native Node.js fetch implementation but until we can reliably get access to the set-cookie response header this will not be possible.
The text was updated successfully, but these errors were encountered:
Since Node.js 17.5, we can pass
--experimental-fetch
to use the built-in undicifetch
implementation.Sadly even if fetch-cookie now theoretically supports WHATWG
fetch
standard (throughresponse.headers.get('set-cookie')
andsplitCookieString
), undici in most cases drop theset-cookie
header, most likely because the spec says it's a forbidden header, and fetch-cookie cannot work with it.As pointed out by @justingrant in whatwg/fetch#1384 (comment) (I'm following up here because this discussion is off topic for the linked issue), undici do expose the
set-cookie
header in some cases.That's a good news but from my testing, the
set-cookie
header is not always returned. It seem to be related toresponseTainting
and the CORS implementation of undici but I couldn't figure precisely in what conditions undici will or will not drop theset-cookie
header.Typically in the earlier URL
https://wikipedia.com/
, it issues a redirect tohttps://www.wikipedia.org/
which is the actual response setting the cookie, as shown by:But fetching that URL with undici returns
null
for theset-cookie
header:Also every test I've done on a
http://localhost
URL failed to return aset-cookie
header with undici:And the same goes for every request I've done with
redirect: 'manual'
, which is a requirement for fetch-cookie to do its job.I'd love fetch-cookie to eventually work with the native Node.js
fetch
implementation but until we can reliably get access to theset-cookie
response header this will not be possible.The text was updated successfully, but these errors were encountered: