Skip to content

Commit

Permalink
avoid re-instantiating Response when not required
Browse files Browse the repository at this point in the history
  • Loading branch information
sassanh committed Nov 3, 2024
1 parent 96c331d commit a5bc739
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
18 changes: 10 additions & 8 deletions packages/next-on-pages/templates/_worker.js/handleRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
3 changes: 3 additions & 0 deletions packages/next-on-pages/templates/_worker.js/utils/routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ export async function runOrFetchBuildOutputItem(
return new Response('Internal Server Error', { status: 500 });
}

if (resp.status === 101) {
return resp;
}
return createMutableResponse(resp);
}

Expand Down

0 comments on commit a5bc739

Please sign in to comment.