Skip to content

Don't write a response body for null body status codes in sendStatus - #336

Open
programmer4285 wants to merge 1 commit into
jeremydaly:mainfrom
programmer4285:null-body-status-codes
Open

Don't write a response body for null body status codes in sendStatus#336
programmer4285 wants to merge 1 commit into
jeremydaly:mainfrom
programmer4285:null-body-status-codes

Conversation

@programmer4285

Copy link
Copy Markdown

resolves #335

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 use statusBodyLookup instead of statusLookup.
  • Added unit tests covering statusBodyLookup for 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 thread src/lib/utils.js
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 thread __tests__/utils.unit.js
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 thread src/lib/response.js
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));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] sendStatus writes a response body for status codes that should not have a body

3 participants