Skip to content

Commit 2ca64db

Browse files
JLewinskibenmccannRich-Harris
authored
fix: cookies and immutable headers (#13942)
* Add Cookie Error When making a request via the event.fetch to the same exact domain the svelte app is running on, it fails returning a 500 due to the header being immutable. This only happens when a cookie is set in the hooks before trying to make a request with the event.fetch * Add Changeset * Update .changeset/breezy-poets-grow.md Co-authored-by: Ben McCann <[email protected]> * Sub Requests have immutable headers From my testing, all sub requests have immutable errors and will fail if cookies are added to them. This will add a check to skip adding the cookies if it is a sub request. * New Response Object Use a new response object to avoid the headers being immutable when adding new cookies. * Format * New Response Object v2 Looked more at other code and found another place where a new response object is created. I based these changes on that to limit the amount of code being changed. * Update .changeset/breezy-poets-grow.md Co-authored-by: Ben McCann <[email protected]> * Only create copy if it is from fetch * Update packages/kit/src/runtime/server/respond.js * tweak * Update .changeset/breezy-poets-grow.md --------- Co-authored-by: Ben McCann <[email protected]> Co-authored-by: Rich Harris <[email protected]> Co-authored-by: Rich Harris <[email protected]>
1 parent c2d1e9e commit 2ca64db

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

.changeset/breezy-poets-grow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
fix: clone `fetch` responses so that headers are mutable

packages/kit/src/runtime/server/respond.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,10 @@ export async function internal_respond(request, options, manifest, state) {
682682

683683
// we can't load the endpoint from our own manifest,
684684
// so we need to make an actual HTTP request
685-
return await fetch(request);
685+
const response = await fetch(request);
686+
687+
// clone the response so that headers are mutable (https://github.com/sveltejs/kit/issues/13857)
688+
return new Response(response.body, response);
686689
} catch (e) {
687690
// TODO if `e` is instead named `error`, some fucked up Vite transformation happens
688691
// and I don't even know how to describe it. need to investigate at some point

0 commit comments

Comments
 (0)