Skip to content

Commit 92f7e5a

Browse files
ZarelMayaLekova
authored andcommitted
doc: improve http.request documentation
PR-URL: nodejs#18289 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent 12d554c commit 92f7e5a

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

doc/api/http.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1878,6 +1878,49 @@ const req = http.request(options, (res) => {
18781878
});
18791879
```
18801880

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

0 commit comments

Comments
 (0)