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
Currently, if you attempt to iterate over a Headers object in a worker with multiple Set-Cookie values, the iterator will only yield a single, comma-delimited value (which breaks the Set-Cookie header) instead of multiple, independent values.
For example:
constheaders=newHeaders();headers.append("Set-Cookie","A=1");headers.append("Set-Cookie","B=2");console.log("Headers from Headers.entries:")for(const[k,v]ofheaders.entries()){console.log(`${k}: ${v}`);}console.log("\nHeaders from Headers.forEach:")headers.forEach((v,k)=>{console.log(`${k}: ${v}`);});
Expected outcome:
Headers from Headers.entries:
set-cookie: A=1
set-cookie: B=2
Headers from Headers.forEach:
set-cookie: A=1
set-cookie: B=2
Actual outcome:
Headers from Headers.entries:
set-cookie: A=1, B=2
Headers from Headers.forEach:
set-cookie: A=1, B=2
While this could be worked around using Headers.getAll for the Set-Cookie header as documented here, supporting iterators for Set-Cookie would make it much easier to do things like merge multiple Headers objects and read all headers at once without breaking anything.
The text was updated successfully, but these errors were encountered:
I agree that would be a better API. However, unfortunately, this is governed by the spec and not something we can change.
The handling of Set-Cookie in the Headers API is a contentious subject, given that this header is the only known header that breaks HTTP's comma-concatenation rule, and this header is also never visible directly from browser-side JS, therefore the browser designers prefer to ignore it. See e.g.: whatwg/fetch#973
We support getAll() as a work-around, since it doesn't create any incompatibility with the spec (in fact, it was once part of the spec, though removed).
In contrast, changing the way iterators work such that the same key could be returned multiple times would be a pretty clear spec violation, conceivably leading to bugs in applications that aren't expecting this. If we really wanted to provide a way to iterate in this way, we'd probably have to give it a different name, like entriesWithMultipleSetCookie() or something. I don't really think this would be worth it, I think apps will just have to special-case Set-Cookie and use getAll() to handle it.
Currently, if you attempt to iterate over a
Headers
object in a worker with multiple Set-Cookie values, the iterator will only yield a single, comma-delimited value (which breaks the Set-Cookie header) instead of multiple, independent values.For example:
Expected outcome:
Actual outcome:
While this could be worked around using
Headers.getAll
for the Set-Cookie header as documented here, supporting iterators for Set-Cookie would make it much easier to do things like merge multipleHeaders
objects and read all headers at once without breaking anything.The text was updated successfully, but these errors were encountered: