Skip to content
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 immutable headers by using a new response object
6 changes: 6 additions & 0 deletions packages/kit/src/runtime/server/respond.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,12 @@ export async function respond(request, options, manifest, state) {
// e.g. accessible when loading modules needed to handle the request
with_event(null, () =>
resolve(event, page_nodes, opts).then((response) => {
response = new Response(response.body, {
status: response.status,
statusText: response.statusText,
headers: new Headers(response.headers)
});

// add headers/cookies here, rather than inside `resolve`, so that we
// can do it once for all responses instead of once per `return`
for (const key in headers) {
Expand Down
Loading