Skip to content

Commit 69a8af0

Browse files
committed
http: doc deprecate abort and improve docs
Doc deprecates ClientRequest.abort in favor of ClientRequest.destroy. Also improves event order documentation for abort and destroy. Refs: nodejs#32225
1 parent aeb7084 commit 69a8af0

File tree

2 files changed

+57
-4
lines changed

2 files changed

+57
-4
lines changed

doc/api/deprecations.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2651,6 +2651,20 @@ written twice. This introduces a race condition between threads, and is a
26512651
potential security vulnerability. There is no safe, cross-platform alternative
26522652
API.
26532653
2654+
2655+
<a id="DEPXXX"></a>
2656+
### DEPXXX: Use `request.destroy()` in favor of `request.abort()`
2657+
<!-- YAML
2658+
changes:
2659+
- version: REPLACEME
2660+
pr-url: https://github.com/nodejs/node/pull/32807
2661+
description: Documentation-only deprecation.
2662+
-->
2663+
2664+
Type: Documentation-only
2665+
2666+
Use [`request.destroy()`][] in favor of [`request.abort()`][].
2667+
26542668
[`--pending-deprecation`]: cli.html#cli_pending_deprecation
26552669
[`--throw-deprecation`]: cli.html#cli_throw_deprecation
26562670
[`Buffer.allocUnsafeSlow(size)`]: buffer.html#buffer_class_method_buffer_allocunsafeslow_size
@@ -2712,8 +2726,10 @@ API.
27122726
[`punycode`]: punycode.html
27132727
[`require.extensions`]: modules.html#modules_require_extensions
27142728
[`require.main`]: modules.html#modules_accessing_the_main_module
2729+
[`request.abort()`]: http.html#http_request_abort
27152730
[`request.socket`]: http.html#http_request_socket
27162731
[`request.connection`]: http.html#http_request_connection
2732+
[`request.destroy()`]: http.html#http_request_destroy_err_callback
27172733
[`response.socket`]: http.html#http_response_socket
27182734
[`response.connection`]: http.html#http_response_connection
27192735
[`response.end()`]: http.html#http_response_end_data_encoding_callback

doc/api/http.md

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,7 @@ server.listen(1337, '127.0.0.1', () => {
568568
### `request.abort()`
569569
<!-- YAML
570570
added: v0.3.8
571+
deprecated: REPLACEME
571572
-->
572573

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

2359-
If `req.abort()` is called before the connection succeeds, the following events
2360-
will be emitted in the following order:
2360+
2361+
If `req.destroy()` is called before a socket is assigned, the following
2362+
events will be emitted in the following order:
2363+
2364+
* (`req.destroy()` called here)
2365+
* `'error'` with an error with message `'Error: socket hang up'` and code
2366+
`'ECONNRESET'`
2367+
* `'close'`
2368+
2369+
If `req.destroy()` is called before the connection succeeds, the following
2370+
events will be emitted in the following order:
2371+
2372+
* `'socket'`
2373+
* (`req.destroy()` called here)
2374+
* `'error'` with an error with message `'Error: socket hang up'` and code
2375+
`'ECONNRESET'`
2376+
* `'close'`
2377+
2378+
If `req.destroy()` is called after the response is received, the following
2379+
events will be emitted in the following order:
2380+
2381+
* `'socket'`
2382+
* `'response'`
2383+
* `'data'` any number of times, on the `res` object
2384+
* (`req.destroy()` called here)
2385+
* `'aborted'` on the `res` object
2386+
* `'close'`
2387+
* `'close'` on the `res` object
2388+
2389+
If `req.abort()` is called before a socket is assigned, the following
2390+
events will be emitted in the following order:
2391+
2392+
* (`req.abort()` called here)
2393+
* `'abort'`
2394+
* `'close'`
2395+
2396+
If `req.abort()` is called before the connection succeeds, the following
2397+
events will be emitted in the following order:
23612398

23622399
* `'socket'`
23632400
* (`req.abort()` called here)
@@ -2366,8 +2403,8 @@ will be emitted in the following order:
23662403
`'ECONNRESET'`
23672404
* `'close'`
23682405

2369-
If `req.abort()` is called after the response is received, the following events
2370-
will be emitted in the following order:
2406+
If `req.abort()` is called after the response is received, the following
2407+
events will be emitted in the following order:
23712408

23722409
* `'socket'`
23732410
* `'response'`

0 commit comments

Comments
 (0)