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

doc: improve http.request documentation #18289

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
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