Skip to content

Default node:http statusMessage to the status code's reason phrase - #8764

Merged
littledivy merged 1 commit into
mainfrom
littledivy/2026-11-21-node-http-status-text
Nov 25, 2026
Merged

littledivy merged 1 commit into
mainfrom
littledivy/2026-11-21-node-http-status-text

Conversation

@littledivy

@littledivy littledivy commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

ServerResponse started with statusMessage set to 'unknown'. writeHead() only fills in STATUS_CODES[statusCode] when statusMessage is empty, so a server that never set it answered HTTP/1.1 200 unknown. Node.js starts statusMessage as undefined and answers 200 OK.

In this patch statusMessage starts undefined, as in Node.js. A message the app sets, or a reason passed to writeHead(), still wins, and a code with no standard phrase still falls back to 'unknown'. The new test in http-server-nodejs-test.js checks 200, 404 and a custom message, and fails without the fix.

This changes the status text existing Workers send, and statusMessage reads as undefined before the headers are written. Both match Node.js, and 'unknown' is not a value code is likely to depend on, so this takes that risk without a compat flag.

Fixes #8737

@littledivy
littledivy requested review from a team as code owners November 21, 2026 02:56

@clanky-the-clanker clanky-the-clanker Bot 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.

Superseded by the review of b8effe1b.

This review, of 82271fd3

💬 Approved with comments — Correct, well-tested fix that brings statusMessage in line with Node.js. One INFO note asks for the commit message to record the compatibility decision.

Findings: 1 info (1 is an inline comment on the diff)

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


📋 Code Quality: 💬 1 info

The fix is correct and the new test covers it. One INFO note about recording the compatibility decision.

Recommendation: 💬 Optional Nits

  • [INFO] Visible behaviour change (statusText 'unknown' → standard phrase; statusMessage undefined before writeHead()) has no compat flag or recorded risk acceptance in the commit message (src/node/internal/internal_http_server.ts:443)
View full review
  • Leaving statusMessage undefined at first lets writeHead() (line 723, this.statusMessage ||= STATUS_CODES[...] || 'unknown') pick up the standard reason phrase. Explicit reasons and app-set messages still take precedence, and non-standard codes still get 'unknown'.
  • The new test checks the default 200 OK, 404 Not Found, a custom message, and that statusMessage is undefined before writeHead() runs.
  • The change is visible to existing Workers: statusText goes from 'unknown' to the standard phrase, and res.statusMessage read before writeHead() is now undefined instead of 'unknown'. The repository's backward-compatibility guidelines ask for this decision to be recorded in the commit message, either as a compat flag or as an accepted risk.

✅ All other checks passed

📝 Documentation: ✅ LGTM

The new code comment describes the current behaviour accurately.


Reviewed commit: 82271fd3

@littledivy
littledivy force-pushed the littledivy/2026-11-21-node-http-status-text branch from 82271fd to b8effe1 Compare November 21, 2026 03:00

@clanky-the-clanker clanky-the-clanker Bot 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.

Superseded by the review of 26ab3250.

This review, of b8effe1b

💬 Approved with comments — Correct, well-tested fix that brings statusMessage in line with Node.js. One INFO note asks for the commit message to record the compatibility decision.

Findings: 1 info

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


📋 Code Quality: 💬 1 info

The fix is correct and the new test covers it. One INFO note about recording the compatibility decision.

Recommendation: 💬 Optional Nits

  • [INFO] Visible behaviour change (statusText 'unknown' → standard phrase; statusMessage undefined before writeHead()) has no compat flag or recorded risk acceptance in the commit message (src/node/internal/internal_http_server.ts:443)
View full review
  • Leaving statusMessage undefined at first lets writeHead() (line 723, this.statusMessage ||= STATUS_CODES[...] || 'unknown') pick up the standard reason phrase. Explicit reasons and app-set messages still take precedence, and non-standard codes still get 'unknown'.
  • The new test checks the default 200 OK, 404 Not Found, a custom message, and that statusMessage is undefined before writeHead() runs.
  • The change is visible to existing Workers: statusText goes from 'unknown' to the standard phrase, and res.statusMessage read before writeHead() is now undefined instead of 'unknown'. The repository's backward-compatibility guidelines ask for this decision to be recorded in the commit message, either as a compat flag or as an accepted risk.

✅ All other checks passed

📝 Documentation: ✅ LGTM

The new code comment describes the current behaviour accurately.


Reviewed commit: b8effe1b — same changes as 82271fd3, so this is that commit's review (no new review was run; line numbers are as of 82271fd3)

ServerResponse started with statusMessage set to 'unknown'. writeHead()
only fills in STATUS_CODES[statusCode] when statusMessage is empty, so a
server that never set it answered "HTTP/1.1 200 unknown". Node.js starts
statusMessage as undefined and answers "200 OK".

In this patch statusMessage starts undefined, as in Node.js. A message
the app sets, or a reason passed to writeHead(), still wins, and a code
with no standard phrase still falls back to 'unknown'.

This changes the status text existing Workers send, and statusMessage
reads as undefined before the headers are written. Both match Node.js,
and 'unknown' is not a value code is likely to depend on, so this takes
that risk without a compat flag.

Fixes #8737
@littledivy
littledivy force-pushed the littledivy/2026-11-21-node-http-status-text branch from b8effe1 to 26ab325 Compare November 21, 2026 03:10

@clanky-the-clanker clanky-the-clanker Bot 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.

✅ Approved — A correct, well-tested fix that matches Node.js behaviour. The test expectation updates are consistent with the shorter status line, and the commit message now records the compatibility decision.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

📋 Code Quality: ✅ LGTM

statusMessage now starts as undefined, so writeHead() fills in the reason phrase from STATUS_CODES, with 'unknown' still used for non-standard codes. An explicit reason or an app-set message takes precedence. The header-character check and the status line both run after statusMessage is set. The writableLength expectations in response-body.js drop by 5, which matches the shorter status line. The new test covers the default, 404 and custom-message cases. The commit message and description now record the compatibility decision.


📝 Documentation: ✅ LGTM

The code comment accurately describes the current behaviour.


Reviewed commit: 26ab3250

@littledivy
littledivy merged commit ded82d6 into main Nov 25, 2026
23 checks passed
@littledivy
littledivy deleted the littledivy/2026-11-21-node-http-status-text branch November 25, 2026 05:52
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 Report — Runtime APIs: node:http ServerResponse sends the status text unknown when the app sets no status message

2 participants