From 632c4317232a96cb6c75f5415322adc79d594ac8 Mon Sep 17 00:00:00 2001 From: lightning4747 Date: Wed, 2 Dec 2026 19:21:40 +0530 Subject: [PATCH] doc: clarify sendingHeaders listener timing Assisted-by: Codex Signed-off-by: lightning4747 --- doc/api/http.md | 7 ++++--- doc/api/http2.md | 6 ++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/doc/api/http.md b/doc/api/http.md index 930772170b7..d84ae170829 100644 --- a/doc/api/http.md +++ b/doc/api/http.md @@ -2127,9 +2127,10 @@ Because it is a single emission point, multiple independent listeners (for example logging, session, and content-negotiation middleware) can each register without coordinating with one another. Listeners run in registration order. -The listener runs synchronously and must not be an `async` function: work -deferred past an `await` runs after the headers are already sent, so only -changes made synchronously take effect. +Node.js calls listeners synchronously and does not wait for promises they +return. Header and status changes must happen during the synchronous part of +the listener: work deferred past an `await` runs after the headers are already +sent, so only synchronous changes take effect. ```js const server = http.createServer((req, res) => { diff --git a/doc/api/http2.md b/doc/api/http2.md index 5d45b0fef70..af8b897cbc0 100644 --- a/doc/api/http2.md +++ b/doc/api/http2.md @@ -4681,8 +4681,10 @@ The event is reached by every header-flushing path ([`response.writeHead()`][], implicit headers from the first [`response.write()`][] or [`response.end()`][], and `response.flushHeaders()`), so independent middleware can each register a listener without coordinating. -Listeners run in registration order and must be synchronous; changes deferred -past an `await` run after the headers are already sent and have no effect. +Listeners run in registration order. Node.js calls them synchronously and does +not wait for promises they return. Header and status changes must happen during +the synchronous part of the listener: work deferred past an `await` runs after +the headers are already sent, so only synchronous changes take effect. This is the HTTP/2 counterpart of the HTTP/1 [`'sendingHeaders'`](http.md#event-sendingheaders) event.