Skip to content

Commit

Permalink
Disallowing response body on null body status codes
Browse files Browse the repository at this point in the history
  • Loading branch information
tsndr committed Jun 8, 2022
1 parent 7b0540c commit ae0c933
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,16 +385,16 @@ class Router {
return res.raw
}

const resInit = {
const resOpts = {
status: res.status || (res.body ? 200 : 204),
headers: res.headers
}

if (res.webSocket) {
resInit.webSocket = res.webSocket
resOpts.webSocket = res.webSocket
}

return new Response(res.body, resInit)
return new Response([101, 204, 205, 304].includes(resOpts.status) ? null : res.body, resOpts)
} catch(err) {
console.error(err)
return new Response(this.debugMode ? err.stack : '', { status: 500 })
Expand Down

0 comments on commit ae0c933

Please sign in to comment.