0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00

doc: improve http.request documentation

PR-URL: https://github.com/nodejs/node/pull/18289
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
Guangcong Luo 2018-01-07 18:43:39 -06:00 committed by Anna Henningsen
parent c9ce5c33dc
commit 27ee08363b
No known key found for this signature in database
GPG Key ID: 9C63F3A6CD2AD8F9

View File

@ -1878,6 +1878,49 @@ const req = http.request(options, (res) => {
});
```
In a successful request, the following events will be emitted in the following
order:
* `socket`
* `response`
* `data` any number of times, on the `res` object
(`data` will not be emitted at all if the response body is empty, for
instance, in most redirects)
* `end` on the `res` object
* `close`
In the case of a connection error, the following events will be emitted:
* `socket`
* `error`
* `close`
If `req.abort()` is called before the connection succeeds, the following events
will be emitted in the following order:
* `socket`
* (`req.abort()` called here)
* `abort`
* `close`
* `error` with an error with message `Error: socket hang up` and code
`ECONNRESET`
If `req.abort()` is called after the response is received, the following events
will be emitted in the following order:
* `socket`
* `response`
* `data` any number of times, on the `res` object
* (`req.abort()` called here)
* `abort`
* `close`
* `aborted` on the `res` object
* `end` on the `res` object
* `close` on the `res` object
Note that setting the `timeout` option or using the `setTimeout` function will
not abort the request or do anything besides add a `timeout` event.
[`'checkContinue'`]: #http_event_checkcontinue
[`'request'`]: #http_event_request
[`'response'`]: #http_event_response