diff --git a/doc/api/http.md b/doc/api/http.md index f7355e0fbe6630..213c38fcefad0e 100644 --- a/doc/api/http.md +++ b/doc/api/http.md @@ -286,9 +286,9 @@ added: v0.1.17 This object is created internally and returned from [`http.request()`][]. It represents an _in-progress_ request whose header has already been queued. The -header is still mutable using the `setHeader(name, value)`, `getHeader(name)`, -`removeHeader(name)` API. The actual header will be sent along with the first -data chunk or when calling [`request.end()`][]. +header is still mutable using the [`setHeader(name, value)`][], + [`getHeader(name)`][], [`removeHeader(name)`][] API. The actual header will +be sent along with the first data chunk or when calling [`request.end()`][]. To get the response, add a listener for [`'response'`][] to the request object. [`'response'`][] will be emitted from the request object when the response @@ -552,6 +552,58 @@ That's usually desired (it saves a TCP round-trip), but not when the first data is not sent until possibly much later. `request.flushHeaders()` bypasses the optimization and kickstarts the request. +### request.getHeader(name) + + +* `name` {string} +* Returns: {string} + +Reads out a header on the request. Note that the name is case insensitive. + +Example: +```js +const contentType = request.getHeader('Content-Type'); +``` + +### request.removeHeader(name) + + +* `name` {string} + +Removes a header that's already defined into headers object. + +Example: +```js +request.removeHeader('Content-Type'); +``` + +### request.setHeader(name, value) + + +* `name` {string} +* `value` {string} + +Sets a single header value for headers object. If this header already exists in +the to-be-sent headers, its value will be replaced. Use an array of strings +here to send multiple headers with the same name. + +Example: +```js +request.setHeader('Content-Type', 'application/json'); +``` + +or + +```js +request.setHeader('Set-Cookie', ['type=ninja', 'language=javascript']); +``` + ### request.setNoDelay([noDelay])