Skip to content

Commit 31c797c

Browse files
ronagBethGriggs
authored andcommitted
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: #32225 PR-URL: #32807 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Zeyu Yang <himself65@outlook.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent f116825 commit 31c797c

File tree

2 files changed

+83
-4
lines changed

2 files changed

+83
-4
lines changed

doc/api/deprecations.md

+15
Original file line numberDiff line numberDiff line change
@@ -2651,6 +2651,19 @@ 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+
<a id="DEP0XXX"></a>
2655+
### DEP0XXX: Use `request.destroy()` instead of `request.abort()`
2656+
<!-- YAML
2657+
changes:
2658+
- version: REPLACEME
2659+
pr-url: https://github.com/nodejs/node/pull/32807
2660+
description: Documentation-only deprecation.
2661+
-->
2662+
2663+
Type: Documentation-only
2664+
2665+
Use [`request.destroy()`][] instead of [`request.abort()`][].
2666+
26542667
[`--pending-deprecation`]: cli.html#cli_pending_deprecation
26552668
[`--throw-deprecation`]: cli.html#cli_throw_deprecation
26562669
[`Buffer.allocUnsafeSlow(size)`]: buffer.html#buffer_class_method_buffer_allocunsafeslow_size
@@ -2712,8 +2725,10 @@ API.
27122725
[`punycode`]: punycode.html
27132726
[`require.extensions`]: modules.html#modules_require_extensions
27142727
[`require.main`]: modules.html#modules_accessing_the_main_module
2728+
[`request.abort()`]: http.html#http_request_abort
27152729
[`request.socket`]: http.html#http_request_socket
27162730
[`request.connection`]: http.html#http_request_connection
2731+
[`request.destroy()`]: http.html#http_request_destroy_error
27172732
[`response.socket`]: http.html#http_response_socket
27182733
[`response.connection`]: http.html#http_response_connection
27192734
[`response.end()`]: http.html#http_response_end_data_encoding_callback

doc/api/http.md

+68-4
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
@@ -623,6 +624,31 @@ If `data` is specified, it is equivalent to calling
623624
If `callback` is specified, it will be called when the request stream
624625
is finished.
625626

627+
### `request.destroy([error])`
628+
<!-- YAML
629+
added: v0.3.0
630+
-->
631+
632+
* `error` {Error} Optional, an error to emit with `'error'` event.
633+
* Returns: {this}
634+
635+
Destroy the request. Optionally emit an `'error'` event,
636+
and emit a `'close'` event. Calling this will cause remaining data
637+
in the response to be dropped and the socket to be destroyed.
638+
639+
See [`writable.destroy()`][] for further details.
640+
641+
#### `request.destroyed`
642+
<!-- YAML
643+
added: REPLACEME
644+
-->
645+
646+
* {boolean}
647+
648+
Is `true` after [`request.destroy()`][] has been called.
649+
650+
See [`writable.destroyed`][] for further details.
651+
626652
### `request.finished`
627653
<!-- YAML
628654
added: v0.0.1
@@ -2354,8 +2380,43 @@ the following events will be emitted in the following order:
23542380
* `'close'`
23552381
* `'close'` on the `res` object
23562382

2357-
If `req.abort()` is called before the connection succeeds, the following events
2358-
will be emitted in the following order:
2383+
If `req.destroy()` is called before a socket is assigned, the following
2384+
events will be emitted in the following order:
2385+
2386+
* (`req.destroy()` called here)
2387+
* `'error'` with an error with message `'Error: socket hang up'` and code
2388+
`'ECONNRESET'`
2389+
* `'close'`
2390+
2391+
If `req.destroy()` is called before the connection succeeds, the following
2392+
events will be emitted in the following order:
2393+
2394+
* `'socket'`
2395+
* (`req.destroy()` called here)
2396+
* `'error'` with an error with message `'Error: socket hang up'` and code
2397+
`'ECONNRESET'`
2398+
* `'close'`
2399+
2400+
If `req.destroy()` is called after the response is received, the following
2401+
events will be emitted in the following order:
2402+
2403+
* `'socket'`
2404+
* `'response'`
2405+
* `'data'` any number of times, on the `res` object
2406+
* (`req.destroy()` called here)
2407+
* `'aborted'` on the `res` object
2408+
* `'close'`
2409+
* `'close'` on the `res` object
2410+
2411+
If `req.abort()` is called before a socket is assigned, the following
2412+
events will be emitted in the following order:
2413+
2414+
* (`req.abort()` called here)
2415+
* `'abort'`
2416+
* `'close'`
2417+
2418+
If `req.abort()` is called before the connection succeeds, the following
2419+
events will be emitted in the following order:
23592420

23602421
* `'socket'`
23612422
* (`req.abort()` called here)
@@ -2364,8 +2425,8 @@ will be emitted in the following order:
23642425
`'ECONNRESET'`
23652426
* `'close'`
23662427

2367-
If `req.abort()` is called after the response is received, the following events
2368-
will be emitted in the following order:
2428+
If `req.abort()` is called after the response is received, the following
2429+
events will be emitted in the following order:
23692430

23702431
* `'socket'`
23712432
* `'response'`
@@ -2411,6 +2472,7 @@ not abort the request or do anything besides add a `'timeout'` event.
24112472
[`new URL()`]: url.html#url_constructor_new_url_input_base
24122473
[`removeHeader(name)`]: #http_request_removeheader_name
24132474
[`request.end()`]: #http_request_end_data_encoding_callback
2475+
[`request.destroy()`]: #http_request_destroy_error
24142476
[`request.flushHeaders()`]: #http_request_flushheaders
24152477
[`request.getHeader()`]: #http_request_getheader_name
24162478
[`request.setHeader()`]: #http_request_setheader_name_value
@@ -2440,5 +2502,7 @@ not abort the request or do anything besides add a `'timeout'` event.
24402502
[`socket.unref()`]: net.html#net_socket_unref
24412503
[`url.parse()`]: url.html#url_url_parse_urlstring_parsequerystring_slashesdenotehost
24422504
[`HPE_HEADER_OVERFLOW`]: errors.html#errors_hpe_header_overflow
2505+
[`writable.destroy()`]: stream.html#stream_writable_destroy_error
2506+
[`writable.destroyed`]: stream.html#stream_writable_destroyed
24432507
[`writable.cork()`]: stream.html#stream_writable_cork
24442508
[`writable.uncork()`]: stream.html#stream_writable_uncork

0 commit comments

Comments
 (0)