Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http.ClientRequest doc update #5719

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 76 additions & 1 deletion doc/api/http.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,36 @@ srv.listen(1337, '127.0.0.1', () => {
Marks the request as aborting. Calling this will cause remaining data
in the response to be dropped and the socket to be destroyed.

### request.addTrailers(headers)

This method adds HTTP trailing headers (a header but at the end of the
message) to the response.

Trailers will **only** be emitted if chunked encoding is used for the
response; if it is not (e.g., if the request was HTTP/1.0), they will
be silently discarded.

Note that HTTP requires the `Trailer` header to be sent if you intend to
emit trailers, with a list of the header fields in its value.

Example:

```js
var request = http.request({
method: 'POST',
headers: {
'Content-Type': 'text/plain',
'Trailer': 'Content-MD5'
}
});
request.write(fileData);
request.addTrailers({'Content-MD5': '7895bf4b8828b55ceaf47747b4bca667'});
request.end();
```

Attempting to set a header field name or value that contains invalid characters
will result in a [`TypeError`][] being thrown.

### request.end([data][, encoding][, callback])

Finishes sending the request. If any parts of the body are
Expand All @@ -395,6 +425,49 @@ That's usually what you want (it saves a TCP round-trip) but not when the first
data isn't sent until possibly much later. `request.flushHeaders()` lets you bypass
the optimization and kickstart the request.

### request.getHeader(name)

Reads out a header that's already been queued but not sent to the client. Note
that the name is case insensitive. This can only be called before headers get
implicitly flushed.

Example:

```js
var contentType = request.getHeader('content-type');
```

### request.removeHeader(name)

Removes a header that's queued for implicit sending.

Example:

```js
request.removeHeader('Content-Encoding');
```

### request.setHeader(name, value)

Sets a single header value for implicit headers. If this header already exists
in the to-be-sent headers, its value will be replaced. Use an array of strings
here if you need to send multiple headers with the same name.

Example:

```js
request.setHeader('Content-Type', 'text/html');
```

or

```js
request.setHeader('Set-Cookie', ['type=ninja', 'language=javascript']);
```

Attempting to set a header field name or value that contains invalid characters
will result in a [`TypeError`][] being thrown.

### request.setNoDelay([noDelay])

Once a socket is assigned to this request and is connected
Expand Down Expand Up @@ -668,7 +741,9 @@ response; if it is not (e.g., if the request was HTTP/1.0), they will
be silently discarded.

Note that HTTP requires the `Trailer` header to be sent if you intend to
emit trailers, with a list of the header fields in its value. E.g.,
emit trailers, with a list of the header fields in its value.

Example:

```js
response.writeHead(200, { 'Content-Type': 'text/plain',
Expand Down