Don't write a response body for null body status codes in sendStatus - #336
Open
programmer4285 wants to merge 1 commit into
Open
Don't write a response body for null body status codes in sendStatus#336programmer4285 wants to merge 1 commit into
programmer4285 wants to merge 1 commit into
Conversation
naorpeled
approved these changes
Aug 1, 2026
There was a problem hiding this comment.
Pull request overview
This PR updates sendStatus to avoid emitting a reason-phrase response body for HTTP status codes that must not include content (1xx, 204, 205, 304), aligning the framework’s behavior with RFC 9110 semantics.
Changes:
- Added
statusBodyLookup(status)utility to return an empty string for no-body status codes. - Updated
RESPONSE.sendStatus()to usestatusBodyLookupinstead ofstatusLookup. - Added unit tests covering
statusBodyLookupfor common status codes.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/lib/utils.js | Adds statusBodyLookup to suppress bodies for no-body HTTP status codes. |
| src/lib/response.js | Switches sendStatus to use statusBodyLookup when generating the response body. |
| tests/utils.unit.js | Adds unit tests for the new statusBodyLookup helper. |
Comment on lines
+117
to
+125
| export const statusBodyLookup = (status) => { | ||
| // The following status codes must not have a response body | ||
| // according to rfc 9110 | ||
| if ((100 <= status && status < 200) || [204, 205, 304].includes(status)) { | ||
| return ''; | ||
| } | ||
|
|
||
| return statusLookup(status); | ||
| }; |
Comment on lines
+236
to
+248
| test.each([ | ||
| [100, ""], | ||
| [101, ""], | ||
| [200, "OK"], | ||
| [204, ""], | ||
| [205, ""], | ||
| [304, ""], | ||
| [404, "Not Found"], | ||
| [502, "Bad Gateway"], | ||
| [999, "Unknown"], | ||
| ])("%d", (status, expected) => { | ||
| expect(utils.statusBodyLookup(status)).toBe(expected); | ||
| }); // end it |
Comment on lines
416
to
419
| // Convenience method for sending status codes | ||
| sendStatus(status) { | ||
| this.status(status).send(UTILS.statusLookup(status)); | ||
| this.status(status).send(UTILS.statusBodyLookup(status)); | ||
| } |
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.
resolves #335