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 authored Nov 2, 2024
1 parent 96c331d commit ab0c9a9
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 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);

resp = new Response(resp.body, {
...resp,
status: status || resp.status,
headers: newHeaders,
});
if (status !== null || [...headers.normal].length > 0 || [...headers.important].length > 0) {
const newHeaders = headers.normal;
applyHeaders(newHeaders, resp.headers);
applyHeaders(newHeaders, headers.important);

resp = new Response(resp.body, {
...resp,
status: status || resp.status,
headers: newHeaders,
});
}

return resp;
}

0 comments on commit ab0c9a9

Please sign in to comment.