Skip to content

Commit 36ea472

Browse files
ZarelMylesBorins
authored andcommitted
doc: improve http.request documentation
PR-URL: #18289 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent c61754f commit 36ea472

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

doc/api/http.md

+43
Original file line numberDiff line numberDiff line change
@@ -1880,6 +1880,49 @@ const req = http.request(options, (res) => {
18801880
});
18811881
```
18821882

1883+
In a successful request, the following events will be emitted in the following
1884+
order:
1885+
1886+
* `socket`
1887+
* `response`
1888+
* `data` any number of times, on the `res` object
1889+
(`data` will not be emitted at all if the response body is empty, for
1890+
instance, in most redirects)
1891+
* `end` on the `res` object
1892+
* `close`
1893+
1894+
In the case of a connection error, the following events will be emitted:
1895+
1896+
* `socket`
1897+
* `error`
1898+
* `close`
1899+
1900+
If `req.abort()` is called before the connection succeeds, the following events
1901+
will be emitted in the following order:
1902+
1903+
* `socket`
1904+
* (`req.abort()` called here)
1905+
* `abort`
1906+
* `close`
1907+
* `error` with an error with message `Error: socket hang up` and code
1908+
`ECONNRESET`
1909+
1910+
If `req.abort()` is called after the response is received, the following events
1911+
will be emitted in the following order:
1912+
1913+
* `socket`
1914+
* `response`
1915+
* `data` any number of times, on the `res` object
1916+
* (`req.abort()` called here)
1917+
* `abort`
1918+
* `close`
1919+
* `aborted` on the `res` object
1920+
* `end` on the `res` object
1921+
* `close` on the `res` object
1922+
1923+
Note that setting the `timeout` option or using the `setTimeout` function will
1924+
not abort the request or do anything besides add a `timeout` event.
1925+
18831926
[`'checkContinue'`]: #http_event_checkcontinue
18841927
[`'request'`]: #http_event_request
18851928
[`'response'`]: #http_event_response

0 commit comments

Comments
 (0)