-
Notifications
You must be signed in to change notification settings - Fork 174
avoid creating unnecessary headers instance #1008
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
base: main
Are you sure you want to change the base?
avoid creating unnecessary headers instance #1008
Conversation
🦋 Changeset detectedLatest commit: a955067 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
commit: |
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.
We need to check, I might be wrong, but in some cases we can pass the result of a fetch directly here, and in this case the headers are immutable.
for (const cookie of cookies) { | ||
responseHeaders.append("Set-Cookie", cookie); | ||
} | ||
headers["set-cookie"] = cookies.join(","); |
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.
I think that's wrong.
I you have a=1,b=2
it will create a single a
cookie with the value 1,b=2
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.
> let a = new Headers()
undefined
> a.append('set-cookie', 1)
undefined
> a.append('set-cookie', 2)
undefined
> a
Headers { 'set-cookie': '1, 2' }
This is true. Other than the missing extra space
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.
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.
^ with a space
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.
headers["set-cookie"] = cookies.join(","); | |
headers["set-cookie"] = cookies.join(", "); |
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.
@anonrig Looks like the actual syntax would be: a="1";b="2"
(quotes required)
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.
I see. Let me fix it.
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.
see inline comments
ad2c46b
to
a955067
Compare
// Build headers array - set-cookie must be added separately for each cookie | ||
const headerEntries: [string, string][] = Object.entries(headers); | ||
for (const cookie of cookies) { | ||
headerEntries.push(["set-cookie", cookie]); |
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.
Hmm.. while this might be more efficient I'm not convinced this is right. This is going to end up skipping any kind of validation on the value of cookie
, which could end up causing problems elsewhere.
Let's make sure that we don't copy all of the headers, just to mutate it.
Part of #1002