Skip to content

fix: cookies and immutable headers #13942

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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions .changeset/breezy-poets-grow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: prevent error attempting to modify immutable headers by creating a new `Response` object from the fetch response
9 changes: 8 additions & 1 deletion packages/kit/src/runtime/server/respond.js
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,14 @@ export async function respond(request, options, manifest, state) {

// we can't load the endpoint from our own manifest,
// so we need to make an actual HTTP request
return await fetch(request);
const fetchResponse = await fetch(request);

// the headers for the response needs to be mutable so that cookies can be added
return new Response(fetchResponse.body, {
status: fetchResponse.status,
statusText: fetchResponse.statusText,
headers: new Headers(fetchResponse.headers)
});
} catch (e) {
// TODO if `e` is instead named `error`, some fucked up Vite transformation happens
// and I don't even know how to describe it. need to investigate at some point
Expand Down
Loading