Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit dae86b3

Browse filesBrowse 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 c34e2f4 commit dae86b3
Copy full SHA for dae86b3

File tree

Expand file treeCollapse file tree

1 file changed

+43
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+43
-0
lines changed
Open diff view settings
Collapse file

‎doc/api/http.md‎

Copy file name to clipboardExpand all lines: doc/api/http.md
+43Lines changed: 43 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.