diff --git a/.changeset/breezy-poets-grow.md b/.changeset/breezy-poets-grow.md new file mode 100644 index 000000000000..06135d23f501 --- /dev/null +++ b/.changeset/breezy-poets-grow.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +fix: clone `fetch` responses so that headers are mutable diff --git a/packages/kit/src/runtime/server/respond.js b/packages/kit/src/runtime/server/respond.js index 4e7ead2d4f6e..924c63186869 100644 --- a/packages/kit/src/runtime/server/respond.js +++ b/packages/kit/src/runtime/server/respond.js @@ -682,7 +682,10 @@ export async function internal_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 response = await fetch(request); + + // clone the response so that headers are mutable (https://github.com/sveltejs/kit/issues/13857) + return new Response(response.body, response); } 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