diff options
Diffstat (limited to 'doc')
-rw-r--r-- | doc/api/http.md | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/doc/api/http.md b/doc/api/http.md index 8803078569..87de5a9bba 100644 --- a/doc/api/http.md +++ b/doc/api/http.md @@ -1450,6 +1450,10 @@ the request body should be sent. See the [`'checkContinue'`][] event on <!-- YAML added: v0.1.30 changes: + - version: REPLACEME + pr-url: https://github.com/nodejs/node/pull/25974 + description: Return `this` from `writeHead()` to allow chaining with + `end()`. - version: v5.11.0, v4.4.5 pr-url: https://github.com/nodejs/node/pull/6291 description: A `RangeError` is thrown if `statusCode` is not a number in @@ -1459,17 +1463,23 @@ changes: * `statusCode` {number} * `statusMessage` {string} * `headers` {Object} +* Returns: {http.ServerResponse} Sends a response header to the request. The status code is a 3-digit HTTP status code, like `404`. The last argument, `headers`, are the response headers. Optionally one can give a human-readable `statusMessage` as the second argument. +Returns a reference to the `ServerResponse`, so that calls can be chained. + ```js const body = 'hello world'; -response.writeHead(200, { - 'Content-Length': Buffer.byteLength(body), - 'Content-Type': 'text/plain' }); +response + .writeHead(200, { + 'Content-Length': Buffer.byteLength(body), + 'Content-Type': 'text/plain' + }) + .end(body); ``` This method must only be called once on a message and it must |