-
Notifications
You must be signed in to change notification settings - Fork 545
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cookie
no longer able to be set in the Headers API as of v5.2.0
#1463
Comments
This is expected - undici follows the fetch spec and not how other platforms behave. The fetch spec tells implementations to filter out |
Ok and looks like undici doesn't support |
That section of the code deals with setting cookies in a per-origin browser cookie jar, not getting/setting/sending |
Hello! I'm confused. I was using nodejs v18.0 However now I cannot when I upgraded to nodejs v18.2. I see it when doing a I understand that that's the fetch API standard, but that standards seems like it was designed for a browser, and not Node. (BTW, my use case is proxying a CouchDB POST to So I guess the fetch API is simply not compatible with my use case and I must use a third party library? |
Yes, you are entirely correct. The fetch spec was developed with browsers in mind - not so much a server environment. This causes a few problems with deciding how features should behave when the spec is subpar for a node.js use-case. Some decisions were made to branch away from the spec, however, those decisions were made before the creation of the WinterCG so now it has been decided to wait for a cross-platform solution/"spec", rather than introducing our own. See: #1262 (comment) Re-reading it, if you put in the work, it seems as though a PR will be accepted. Unsure of that though, you can always make a PR for yourself, or wait for me to do it 😛.
|
Thanks for the quick response! That sounds good. In case anyone else is reading and has the same issue, |
Could you open a fresh issue? That should definitely be possible. BTW, I think set-cookie is received, not sent. |
You can actually send import { request } from 'undici'
import { createServer } from 'http';
import { once } from 'events';
const server = createServer((req, res) => {
console.log(req.headers['set-cookie'])
res.end('goodbye')
}).listen(0)
await once(server, 'listening')
await request(`http://localhost:${server.address().port}`, {
headers: {
'set-cookie': 'bar=baz; foo=bar'
}
})
server.close() Outputs:
@aeharding if you don't mind switching from fetch, undici.request has a great api with less restrictions. |
I'm seeing something related in 5.2.0 and 5.3.0 - I was using Headers to pass the headers, and with older versions that allowed me to authenticate but it broke other things. I upgraded to 5.2 and I could no longer authenticate. However, when I change the headers to a plain object with So there is still an issue with Headers and cookies, somehow. |
Okay, hold on. Do you understand what
How would you set cookies according to the In the first place, what’s the point of bringing unnecessary constraints to this? What’s the point of being so obsessed with all the security features that are only meaningful to web browsers? “Because the spec says so?” The specification is intended for browsers. And what is this, a headless browser? It is not feasible at all to imitate what the browser does on Node.js to begin with. Look, this is Node.js’ Please, double please, reconsider the direction of |
I have opened wintercg/fetch#7 to discuss with the WinterCG team. |
Hey, @issuefiler. Node landed an experimental implementation of 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. |
Bug Description
Upgrading Node from 18.1 to 18.2 we are no longer able to set the
cookie
header in theHeaders
API.Seems this is a result of #1337
Reproducible By
Running the above code on Node 18.1:
On Node 18.2 (and undidi 5.2):
Curiously if I don't use the
Headers
API and set thecookie
header directly it works:Expected Behavior
Would expect to be able to still set the
cookie
header because we can't usedocument.cookie
like you can use in browser environments.Environment
nvm
The text was updated successfully, but these errors were encountered: