Skip to content

Commit 9d18408

Browse files
ronagBridgeAR
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 <[email protected]> Reviewed-By: Zeyu Yang <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent 4fc7877 commit 9d18408

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
@@ -2569,6 +2569,19 @@ accordingly instead to avoid the ambigiuty.
25692569
To maintain existing behaviour `response.finished` should be replaced with
25702570
`response.writableEnded`.
25712571
2572+
<a id="DEP0XXX"></a>
2573+
### DEP0XXX: Use `request.destroy()` instead of `request.abort()`
2574+
<!-- YAML
2575+
changes:
2576+
- version: REPLACEME
2577+
pr-url: https://github.com./nodejs/node/pull/32807
2578+
description: Documentation-only deprecation.
2579+
-->
2580+
2581+
Type: Documentation-only
2582+
2583+
Use [`request.destroy()`][] instead of [`request.abort()`][].
2584+
25722585
[`--pending-deprecation`]: cli.html#cli_pending_deprecation
25732586
[`--throw-deprecation`]: cli.html#cli_throw_deprecation
25742587
[`Buffer.allocUnsafeSlow(size)`]: buffer.html#buffer_class_method_buffer_allocunsafeslow_size
@@ -2627,8 +2640,10 @@ To maintain existing behaviour `response.finished` should be replaced with
26272640
[`process.env`]: process.html#process_process_env
26282641
[`punycode`]: punycode.html
26292642
[`require.extensions`]: modules.html#modules_require_extensions
2643+
[`request.abort()`]: http.html#http_request_abort
26302644
[`request.socket`]: http.html#http_request_socket
26312645
[`request.connection`]: http.html#http_request_connection
2646+
[`request.destroy()`]: http.html#http_request_destroy_error
26322647
[`response.socket`]: http.html#http_response_socket
26332648
[`response.connection`]: http.html#http_response_connection
26342649
[`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)