Skip to content

Commit

Permalink
fix(web): use null for null body responses (#495)
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 authored Aug 7, 2023
1 parent f3394ee commit b96aa69
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/adapters/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export function toWebHandler(app: App) {

// --- Internal ---

const nullBodyResponses = new Set([101, 204, 205, 304]);

async function _handleWebRequest(
app: App,
request: Request,
Expand All @@ -35,7 +37,13 @@ async function _handleWebRequest(
body: request.body,
});

return new Response(res.body as BodyInit, {
// https://developer.mozilla.org/en-US/docs/Web/API/Response/body
const body =
nullBodyResponses.has(res.status) || request.method === "HEAD"
? null
: (res.body as BodyInit);

return new Response(body, {
status: res.status,
statusText: res.statusText,
headers: res.headers,
Expand Down

0 comments on commit b96aa69

Please sign in to comment.