Skip to content

http: add writeInformation to send arbitrary 1xx status codes#63155

Open
pimterry wants to merge 1 commit intonodejs:mainfrom
pimterry:h1-additional-headers
Open

http: add writeInformation to send arbitrary 1xx status codes#63155
pimterry wants to merge 1 commit intonodejs:mainfrom
pimterry:h1-additional-headers

Conversation

@pimterry
Copy link
Copy Markdown
Member

@pimterry pimterry commented May 6, 2026

This provides a generic HTTP/1 API for 1xx responses, equivalent to our existing HTTP/2 additionalHeaders API. This supports any 1xx status code, except 101, which I've intentionally excluded - since it changes the protocol entirely, there's no possible way to unilaterally send that without breaking things later in our current API, so you just have to use 'upgrade' in that case.

This fixes various past requests like:

And acts as a nice workaround to solve:

(All 3 closed as stale, not fixed)

I'm also hoping it'll discourage usage of the private res._writeRaw method as a workaround for the existing limitations. We even did this in our own tests, see test/parallel/test-http-information-headers.js here.

This is useful to support custom 1xx values (perfectly valid AFAICT, if unusual), proxies (who want to pass through data in a standard way, without having to separately handle each case individually as today) and to give us trivial general support for future standardized 1xx values, without needing a whole separate PR to add a new per-status API every time.

The existing methods are refactored to use the generic method under the hood, and HTTP/2 compat uses additionalHeaders.

There's one annoying inconsistency here: the H1 methods throw if we've already sent a final status code, while the H2 methods just no-op. I've kept that as-is and matched this in the new method to avoid a breaking change, but it would probably be best to align on throwing in both cases in a separate major bump.

@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/http
  • @nodejs/http2
  • @nodejs/net

@nodejs-github-bot nodejs-github-bot added http Issues or PRs related to the http subsystem. http2 Issues or PRs related to the http2 subsystem. needs-ci PRs that need a full CI run. labels May 6, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 6, 2026

Codecov Report

❌ Patch coverage is 90.47619% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.02%. Comparing base (b5da751) to head (af03c6b).

Files with missing lines Patch % Lines
lib/_http_server.js 85.45% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #63155      +/-   ##
==========================================
- Coverage   90.03%   90.02%   -0.02%     
==========================================
  Files         713      713              
  Lines      224510   224565      +55     
  Branches    42438    42462      +24     
==========================================
+ Hits       202148   202161      +13     
- Misses      14163    14222      +59     
+ Partials     8199     8182      -17     
Files with missing lines Coverage Δ
lib/internal/http2/compat.js 97.10% <100.00%> (+0.13%) ⬆️
lib/_http_server.js 96.61% <85.45%> (-0.33%) ⬇️

... and 31 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Member

@metcoder95 metcoder95 left a comment

Choose a reason for hiding this comment

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

Don't have approval power, but lgtm; nice addition

Signed-off-by: Tim Perry <pimterry@gmail.com>
@pimterry pimterry force-pushed the h1-additional-headers branch from d6b58d7 to af03c6b Compare May 7, 2026 08:20
@pimterry
Copy link
Copy Markdown
Member Author

pimterry commented May 7, 2026

Rebased to hopefully fix the build now that the QUIC coverage issue is sorted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

http Issues or PRs related to the http subsystem. http2 Issues or PRs related to the http2 subsystem. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants