fix: don't write a response body for null body status codes - #342
Merged
naorpeled merged 1 commit intoAug 8, 2026
Merged
Conversation
Status codes that must not carry content per RFC 9110 (1xx, 204, 205, 304) were still emitting a body when set via status() and sent through send(), json(), html(), etc. Moves the check into send() so every response method inherits it, rather than special-casing sendStatus() alone.
There was a problem hiding this comment.
Pull request overview
Broadens #336 by enforcing bodyless HTTP statuses across all response methods.
Changes:
- Centralizes null-body status detection in
send(). - Adds utility and integration tests.
- Updates status documentation.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
src/lib/utils.js |
Adds null-body status detection. |
src/lib/response.js |
Discards prohibited response bodies. |
README.md |
Documents bodyless statuses. |
__tests__/utils.unit.js |
Tests status detection boundaries. |
__tests__/responses.unit.js |
Tests response methods and control behavior. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
naorpeled
force-pushed
the
fix/null-body-status-codes-in-send
branch
from
August 8, 2026 16:16
dc4becd to
7e7d096
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #336, which fixed
sendStatus()for RFC 9110 null body status codes. The same leak is reachable through every other response method:Change
Adds
UTILS.isNullBodyStatus()and applies it once inRESPONSE.send(), sosend/json/jsonp/html/sendFile/errorall inherit the behavior instead of each needing its own special case. Express takes the same approach for the same reason (express/lib/response.js).Notes for review
sendStatus(), so once both landstatusBodyLookupis redundant andsendStatuscan go back tostatusLookup. Happy to rebase and fold that in after Don't write a response body for null body status codes in sendStatus #336 merges — I've left Don't write a response body for null body status codes in sendStatus #336 alone so the original reporter's fix lands on its own.res.status(204).json({...})will silently drop the payload. Express does the same, but for a reason that doesn't transfer — Node'shttplayer physically can't write a body for 204/304, so Express is aligning headers with a reality it can't change. lambda-api is just building a JSON object, so this is a deliberate choice to enforce the spec rather than a constraint. Flagging it explicitly in case you'd rather pass the body through and let callers own the violation.Content-Type/Content-Length/Transfer-Encodingfor these codes. I didn't, to keep the diff to body semantics and because existing 304 ETag responses already includecontent-type(__tests__/etag.unit.js). Easy to add if you want the full Express behavior.Testing
__tests__/responses.unit.jsforjson(),send(),html(), andsendStatus()on null body codes, plus a 200 control case.isNullBodyStatuscovering boundaries (199/200, 203/204/205/206, 303/304/305), string inputs, andnull/undefined.Docs
Updated the
status(code)section of the README — its example wasres.status(304).send('Not Modified'), which this change makes misleading.