Skip to content
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

Properly copy headers to preserve duplicate set-cookie headers. #872

Closed
wants to merge 1 commit into from
Closed

Properly copy headers to preserve duplicate set-cookie headers. #872

wants to merge 1 commit into from

Conversation

evanderkoogh
Copy link
Contributor

Browser have a lot of bugs in relation to parsing concatenated set-cookie headers. This fixes that.

It used the new getAll() method which can be used with the set-cookie header to get an array back. And when using .set and .append, the Worker runtime will emit multiple headers.

This fixes the bug with multiple set-cookie headers that was introduced by #796.

Unfortunately I could not add a test case to the end-to-end tests, because the udici library has no support for getAll(), so I can't determine if the set-cookie headers were concatenated or not.

Browser have a lot of bugs in relation to parsing concatenated set-cookie headers. This fixes that.
@changeset-bot
Copy link

changeset-bot bot commented May 2, 2022

⚠️ No Changeset found

Latest commit: 43c6498

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions
Copy link
Contributor

github-actions bot commented May 2, 2022

A wrangler prerelease is available for testing. You can install this latest build in your project with:

npm install --save-dev https://prerelease-registry.developers.workers.dev/runs/2256106421/npm-package-wrangler-872

You can reference the automatically updated head of this PR with:

npm install --save-dev https://prerelease-registry.developers.workers.dev/prs/872/npm-package-wrangler-872

Or you can use npx with this latest build directly:

npx https://prerelease-registry.developers.workers.dev/runs/2256106421/npm-package-wrangler-872 dev path/to/script.js

@@ -123,7 +161,7 @@ export default {
// https://fetch.spec.whatwg.org/#null-body-status
return new Response(
[101, 204, 205, 304].includes(response.status) ? null : response.body,
{ ...response, headers: new Headers([...response.headers.entries()]) }
{ ...response, headers: copyHeaders(response.headers as Headers) }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually think we can simplify this. I must have been tired when I first wrote this, because apparently just doing new Headers(response.headers) is enough to correctly make a mutable copy of headers.

As explained to me by the ever-helpful champs: https://discord.com/channels/595317990191398933/910978223968518144/970105175924690994

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{ ...response, headers: copyHeaders(response.headers as Headers) }
{ ...response, headers: new Headers(response.headers) }

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the new way:

image

image

vs. the old way:

image

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants