Skip to content

Commit

Permalink
http: doc deprecate abort and improve docs
Browse files Browse the repository at this point in the history
Doc deprecates ClientRequest.abort in favor of
ClientRequest.destroy. Also improves event order
documentation for abort and destroy.

Refs: #32225
  • Loading branch information
ronag committed Apr 13, 2020
1 parent aeb7084 commit 69a8af0
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 4 deletions.
16 changes: 16 additions & 0 deletions doc/api/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -2651,6 +2651,20 @@ written twice. This introduces a race condition between threads, and is a
potential security vulnerability. There is no safe, cross-platform alternative
API.
<a id="DEPXXX"></a>
### DEPXXX: Use `request.destroy()` in favor of `request.abort()`
<!-- YAML
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/32807
description: Documentation-only deprecation.
-->
Type: Documentation-only
Use [`request.destroy()`][] in favor of [`request.abort()`][].
[`--pending-deprecation`]: cli.html#cli_pending_deprecation
[`--throw-deprecation`]: cli.html#cli_throw_deprecation
[`Buffer.allocUnsafeSlow(size)`]: buffer.html#buffer_class_method_buffer_allocunsafeslow_size
Expand Down Expand Up @@ -2712,8 +2726,10 @@ API.
[`punycode`]: punycode.html
[`require.extensions`]: modules.html#modules_require_extensions
[`require.main`]: modules.html#modules_accessing_the_main_module
[`request.abort()`]: http.html#http_request_abort
[`request.socket`]: http.html#http_request_socket
[`request.connection`]: http.html#http_request_connection
[`request.destroy()`]: http.html#http_request_destroy_err_callback
[`response.socket`]: http.html#http_response_socket
[`response.connection`]: http.html#http_response_connection
[`response.end()`]: http.html#http_response_end_data_encoding_callback
Expand Down
45 changes: 41 additions & 4 deletions doc/api/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,7 @@ server.listen(1337, '127.0.0.1', () => {
### `request.abort()`
<!-- YAML
added: v0.3.8
deprecated: REPLACEME
-->

Marks the request as aborting. Calling this will cause remaining data
Expand Down Expand Up @@ -2356,8 +2357,44 @@ the following events will be emitted in the following order:
* `'close'`
* `'close'` on the `res` object

If `req.abort()` is called before the connection succeeds, the following events
will be emitted in the following order:

If `req.destroy()` is called before a socket is assigned, the following
events will be emitted in the following order:

* (`req.destroy()` called here)
* `'error'` with an error with message `'Error: socket hang up'` and code
`'ECONNRESET'`
* `'close'`

If `req.destroy()` is called before the connection succeeds, the following
events will be emitted in the following order:

* `'socket'`
* (`req.destroy()` called here)
* `'error'` with an error with message `'Error: socket hang up'` and code
`'ECONNRESET'`
* `'close'`

If `req.destroy()` 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.destroy()` called here)
* `'aborted'` on the `res` object
* `'close'`
* `'close'` on the `res` object

If `req.abort()` is called before a socket is assigned, the following
events will be emitted in the following order:

* (`req.abort()` called here)
* `'abort'`
* `'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)
Expand All @@ -2366,8 +2403,8 @@ will be emitted in the following order:
`'ECONNRESET'`
* `'close'`

If `req.abort()` is called after the response is received, the following events
will be emitted in the following order:
If `req.abort()` is called after the response is received, the following
events will be emitted in the following order:

* `'socket'`
* `'response'`
Expand Down

0 comments on commit 69a8af0

Please sign in to comment.