-
Notifications
You must be signed in to change notification settings - Fork 22.5k
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
add doc for Headers.getSetCookie() #26161
Conversation
Preview URLs Flaws (1)Note! 1 document with no flaws that don't need to be listed. 🎉 URL:
External URLs (1)URL:
(comment last updated: 2023-04-17 17:10:45) |
AFAICT, this method is intended for server environments, such as Cloudflare workers and Node.js. Client code cannot create or obtain a response with |
Because the const headers = new Headers({
"Set-Cookie": "name=value",
});
headers.getSetCookie(); |
Thanks @Josh-Cena , that makes total sense. |
Thanks @ricea. I've updated the page now; let me know what you think |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm with nitpick
}); | ||
``` | ||
|
||
However, something like the following can be used to query `Set-Cookie` values on the server: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will work in the browser too, so you can remove the words "on the server".
It's only when communicating with the network that the Set-Cookie
header is removed. As long as you stay in JavaScript, you can use it (it's just not very useful).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. I've updated the wording again but tried something slightly different to get all the points across that you made in the above message.
}); | ||
``` | ||
|
||
However, something like the following can be used to query `Set-Cookie` values. This is much more useful on the server, but it would also work on the client. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another random drive-by: the motivation for the method is to retrieve multiple Set-Cookie
values. Would be cool to have an example like that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another random drive-by: the motivation for the method is to retrieve multiple
Set-Cookie
values. Would be cool to have an example like that.
Makes sense; I've updated the second example to show this.
const headers = new Headers({ | ||
"Set-Cookie": "name=value", | ||
"Set-Cookie": "name1=value1", | ||
"Set-Cookie": "name2=value2", | ||
}); | ||
|
||
headers.getSetCookie(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is against how JS object literals work: later properties always override the former, so the Headers
constructor cannot possibly see both properties. You need to set the header later.
const headers = new Headers({
"Set-Cookie": "name1=value1",
});
headers.append("Set-Cookie", "name2=value2");
headers.getSetCookie();
(Can't test because my Chrome Canary doesn't seem to have this yet)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Darnit; that was a silly mistake. This is what happens when you try to do things quickly. Fixed now; thanks ;-)
And I tested the code on my Canary just to make sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Chris and everyone! 👍
Description
The
Headers.getSetCookie()
method has been added to Chrome 113. This PR adds a reference document for this new method.This is a pretty straightforward addition. You can find other useful links in my research document.
One question I had — the
Set-Cookie
header page includes a note:This sounds contradictory to the purpose of
getSetCookie()
— has this note interpreted the spec correctly, and if so, should I update it to listgetSetCookie()
as an exception to this rule?Motivation
Additional details
Related issues and pull requests
Fix #24266