Skip to content

Commit 8e5104b

Browse files
gireeshpunathiltargos
authored andcommitted
doc: explain HTTP writeHead()'s fast path behavior
calling writeHead() into a Response object that has no headers already set causes getHeader() to return undefined, even if the header was set in the writeHead() function call. Explain this behavior as an optimiation as opposed to a bug. Fixes: #10354 PR-URL: #21289 Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Vse Mozhet Byt <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]>
1 parent 75e07fe commit 8e5104b

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

doc/api/http.md

+14
Original file line numberDiff line numberDiff line change
@@ -1271,6 +1271,13 @@ const server = http.createServer((req, res) => {
12711271
});
12721272
```
12731273

1274+
If [`response.writeHead()`][] method is called and this method has not been
1275+
called, it will directly write the supplied header values onto the network
1276+
channel without caching internally, and the [`response.getHeader()`][] on the
1277+
header will not yield the expected result. If progressive population of headers
1278+
is desired with potential future retrieval and modification, use
1279+
[`response.setHeader()`][] instead of [`response.writeHead()`][].
1280+
12741281
### response.setTimeout(msecs[, callback])
12751282
<!-- YAML
12761283
added: v0.9.12
@@ -1438,6 +1445,13 @@ When headers have been set with [`response.setHeader()`][], they will be merged
14381445
with any headers passed to [`response.writeHead()`][], with the headers passed
14391446
to [`response.writeHead()`][] given precedence.
14401447

1448+
If this method is called and [`response.setHeader()`][] has not been called,
1449+
it will directly write the supplied header values onto the network channel
1450+
without caching internally, and the [`response.getHeader()`][] on the header
1451+
will not yield the expected result. If progressive population of headers is
1452+
desired with potential future retrieval and modification, use
1453+
[`response.setHeader()`][] instead.
1454+
14411455
```js
14421456
// returns content-type = text/plain
14431457
const server = http.createServer((req, res) => {

0 commit comments

Comments
 (0)