Skip to content

Commit

Permalink
doc: improve http.request documentation
Browse files Browse the repository at this point in the history
PR-URL: #18289
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
  • Loading branch information
Zarel authored and MylesBorins committed Mar 30, 2018
1 parent c61754f commit 36ea472
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions doc/api/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -1880,6 +1880,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
Expand Down

0 comments on commit 36ea472

Please sign in to comment.