Skip to content

Commit

Permalink
doc: fix http.ClientRequest method descriptions
Browse files Browse the repository at this point in the history
fix documentation for methods getHeader, setHeader and removeHeader
for http.ClientRequest class. The documentation said these functions
can be called but they're wasn't describe into the API description yet.

add parameters and general description for each methods.

PR-URL: #15163
Fixes: #15048
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
  • Loading branch information
antoine-amara authored and jasnell committed Sep 15, 2017
1 parent a901849 commit ca2c73c
Showing 1 changed file with 58 additions and 3 deletions.
61 changes: 58 additions & 3 deletions doc/api/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -542,6 +542,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)
<!-- YAML
added: v1.6.0
-->

* `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)
<!-- YAML
added: v1.6.0
-->

* `name` {string}

Removes a header that's already defined into headers object.

Example:
```js
request.removeHeader('Content-Type');
```

### request.setHeader(name, value)
<!-- YAML
added: v1.6.0
-->

* `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])
<!-- YAML
added: v0.5.9
Expand Down Expand Up @@ -1897,6 +1949,7 @@ const req = http.request(options, (res) => {
[`agent.createConnection()`]: #http_agent_createconnection_options_callback
[`agent.getName()`]: #http_agent_getname_options
[`destroy()`]: #http_agent_destroy
[`getHeader(name)`]: #requestgetheadername
[`http.Agent`]: #http_class_http_agent
[`http.ClientRequest`]: #http_class_http_clientrequest
[`http.IncomingMessage`]: #http_class_http_incomingmessage
Expand All @@ -1911,6 +1964,7 @@ const req = http.request(options, (res) => {
[`net.Server`]: net.html#net_class_net_server
[`net.Socket`]: net.html#net_class_net_socket
[`net.createConnection()`]: net.html#net_net_createconnection_options_connectlistener
[`removeHeader(name)`]: #requestremoveheadername
[`request.end()`]: #http_request_end_data_encoding_callback
[`request.socket`]: #http_request_socket
[`request.socket.getPeerCertificate()`]: tls.html#tls_tlssocket_getpeercertificate_detailed
Expand All @@ -1923,6 +1977,7 @@ const req = http.request(options, (res) => {
[`response.writeContinue()`]: #http_response_writecontinue
[`response.writeHead()`]: #http_response_writehead_statuscode_statusmessage_headers
[`server.timeout`]: #http_server_timeout
[`setHeader(name, value)`]: #requestsetheadername-value
[`socket.setKeepAlive()`]: net.html#net_socket_setkeepalive_enable_initialdelay
[`socket.setNoDelay()`]: net.html#net_socket_setnodelay_nodelay
[`socket.setTimeout()`]: net.html#net_socket_settimeout_timeout_callback
Expand Down

0 comments on commit ca2c73c

Please sign in to comment.