`cookie` no longer able to be set in the Headers API as of v5.2.0
See original GitHub issueBug Description
Upgrading Node from 18.1 to 18.2 we are no longer able to set the cookie
header in the Headers
API.
Seems this is a result of https://github.com/nodejs/undici/pull/1337
Reproducible By
const headers = new Headers();
headers.append('cookie', 'bar=baz; foo=bar');
fetch('https://httpbin.org/cookies', {
headers,
})
.then(res => res.json())
.then(console.log);
Running the above code on Node 18.1:
{ cookies: { bar: 'baz', foo: 'bar' } }
On Node 18.2 (and undidi 5.2):
{ cookies: {} }
Curiously if I don’t use the Headers
API and set the cookie
header directly it works:
fetch('https://httpbin.org/cookies', {
headers: {
cookie: 'bar=baz; foo=bar',
},
})
.then(res => res.json())
.then(console.log);
// { cookies: { bar: 'baz', foo: 'bar' } }
Expected Behavior
Would expect to be able to still set the cookie
header because we can’t use document.cookie
like you can use in browser environments.
Environment
- OSX 11.6
- Node 18.1 and Node 18.2 using
nvm
Issue Analytics
- State:
- Created a year ago
- Reactions:3
- Comments:12 (7 by maintainers)
Top Results From Across the Web
java - Set-Cookie header in Glassfish-5: folding several ...
How to configure Glassfish5 to send several Set-Cookie headers - one for each ... You no longer need that custom nucleus-grizzly-all.jar.
Read more >7 Keys to the Mystery of a Missing Cookie - Medium
7 Keys to the Mystery of a Missing Cookie · 1. SameSite attribute Defaults to Lax · 2. withCredentials is not Set to...
Read more >Set-Cookie - HTTP - MDN Web Docs
The Set-Cookie HTTP response header is used to send a cookie from the server to the user agent, so that the user agent...
Read more >Enabling Cross-Origin Requests in ASP.NET Web API 2
For more information on using Web API and Cross-Origin Requests (CORS) in ... The application does not set any request headers other than ......
Read more >Request and response objects - Django documentation
This document explains the APIs for HttpRequest and HttpResponse objects, ... request.headers {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hey, @issuefiler.
Node landed an experimental implementation of
fetch
given some semantics people think make sense. Part of the fact it’s experimental is because we are explicitly looking for feedback and to see how people think fetch should behave.Please be mindful of how you phrase yourself. Your comment comes off (to me) as harsh whereas this sort of feedback (the technical bits) are welcome. There are many people using Node.js with different requirements, preferences and ideas about what APIs should do and Node.js is happy to listen to those users in good faith and reconsider API choices.
Your comment makes this a bit hard given the tone. If you want effective discourse I recommend you consider a different approach/tone towards the volunteers working on new features for the platform.
That section of the code deals with setting cookies in a per-origin browser cookie jar, not getting/setting/sending
set-cookie
headers. See #1262