From cbe307dc812a9088aa909837b9edd7e728e14953 Mon Sep 17 00:00:00 2001 From: Gireesh Punathil Date: Tue, 12 Jun 2018 10:41:07 -0400 Subject: [PATCH] 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: https://github.com/nodejs/node/issues/10354 PR-URL: https://github.com/nodejs/node/pull/21289 Reviewed-By: Anatoli Papirovski Reviewed-By: James M Snell Reviewed-By: Luigi Pinca Reviewed-By: Timothy Gu Reviewed-By: Vse Mozhet Byt Reviewed-By: Trivikram Kamat --- doc/api/http.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/doc/api/http.md b/doc/api/http.md index 8f2c531713b4f5..ea229ec0b17681 100644 --- a/doc/api/http.md +++ b/doc/api/http.md @@ -1277,6 +1277,13 @@ const server = http.createServer((req, res) => { }); ``` +If [`response.writeHead()`][] method is called and this method has not been +called, it will directly write the supplied header values onto the network +channel without caching internally, and the [`response.getHeader()`][] on the +header will not yield the expected result. If progressive population of headers +is desired with potential future retrieval and modification, use +[`response.setHeader()`][] instead of [`response.writeHead()`][]. + ### response.setTimeout(msecs[, callback])