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

Stop unnecessarily amalgamating duplicate headers in Functions #880

Merged
merged 2 commits into from
May 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/bright-olives-wonder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"wrangler": patch
---

fix: Stop unnecessarily amalgamating duplicate headers in Pages Functions

Previously, `set-cookie` multiple headers would be combined because of unexpected behavior in [the spec](https://github.com/whatwg/fetch/pull/1346).
2 changes: 1 addition & 1 deletion packages/wrangler/pages/functions/template-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export default function (pluginArgs) {
// https://fetch.spec.whatwg.org/#null-body-status
return new Response(
[101, 204, 205, 304].includes(response.status) ? null : response.body,
response
{ ...response, headers: new Headers(response.headers) }
Copy link
Contributor

Choose a reason for hiding this comment

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

So this is the fix?

And the other change is just for consistency?

Or is the other change also fixing something?

Copy link
Member Author

Choose a reason for hiding this comment

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

The bug was introduced in template-worker.ts. And template-plugin.ts was updated for consistency. Both places should now offer mutable headers and keep any duplicate headers.

);
} else {
return next();
Expand Down
2 changes: 1 addition & 1 deletion packages/wrangler/pages/functions/template-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,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: new Headers(response.headers) }
);
} else if (__FALLBACK_SERVICE__) {
// There are no more handlers so finish with the fallback service (`env.ASSETS.fetch` in Pages' case)
Expand Down