@@ -1880,6 +1880,49 @@ const req = http.request(options, (res) => { |
1880 | 1880 | }); |
1881 | 1881 | ``` |
1882 | 1882 |
|
| 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 | + |
1883 | 1926 | [`'checkContinue'`]: #http_event_checkcontinue |
1884 | 1927 | [`'request'`]: #http_event_request |
1885 | 1928 | [`'response'`]: #http_event_response |
|