diff --git a/packages/next-on-pages/templates/_worker.js/handleRequest.ts b/packages/next-on-pages/templates/_worker.js/handleRequest.ts index 418ba249d..2bed3d860 100644 --- a/packages/next-on-pages/templates/_worker.js/handleRequest.ts +++ b/packages/next-on-pages/templates/_worker.js/handleRequest.ts @@ -114,15 +114,17 @@ async function generateResponse( }); } - const newHeaders = headers.normal; - applyHeaders(newHeaders, resp.headers); - applyHeaders(newHeaders, headers.important); + if (status || resp.status !== 101) { + const newHeaders = headers.normal; + applyHeaders(newHeaders, resp.headers); + applyHeaders(newHeaders, headers.important); - resp = new Response(resp.body, { - ...resp, - status: status || resp.status, - headers: newHeaders, - }); + resp = new Response(resp.body, { + ...resp, + status: status || resp.status, + headers: newHeaders, + }); + } return resp; } diff --git a/packages/next-on-pages/templates/_worker.js/utils/routing.ts b/packages/next-on-pages/templates/_worker.js/utils/routing.ts index 100741541..7b8d00e95 100644 --- a/packages/next-on-pages/templates/_worker.js/utils/routing.ts +++ b/packages/next-on-pages/templates/_worker.js/utils/routing.ts @@ -131,7 +131,7 @@ export async function runOrFetchBuildOutputItem( return new Response('Internal Server Error', { status: 500 }); } - return createMutableResponse(resp); + return resp; } /**