mirror of
https://github.com/nodejs/node.git
synced 2025-12-28 07:50:41 +00:00
http: return this from ClientRequest#destroy()
This commit updates ClientRequest#destroy() to return `this` for consistency with other writable streams. PR-URL: https://github.com/nodejs/node/pull/32789 Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
parent
ff6535a433
commit
cad76da198
@ -631,6 +631,11 @@ is finished.
|
||||
### `request.destroy([error])`
|
||||
<!-- YAML
|
||||
added: v0.3.0
|
||||
changes:
|
||||
- version: REPLACEME
|
||||
pr-url: https://github.com/nodejs/node/pull/32789
|
||||
description: The function returns `this` for consistency with other Readable
|
||||
streams.
|
||||
-->
|
||||
|
||||
* `error` {Error} Optional, an error to emit with `'error'` event.
|
||||
|
||||
@ -349,7 +349,7 @@ ClientRequest.prototype.abort = function abort() {
|
||||
|
||||
ClientRequest.prototype.destroy = function destroy(err) {
|
||||
if (this.destroyed) {
|
||||
return;
|
||||
return this;
|
||||
}
|
||||
this.destroyed = true;
|
||||
|
||||
@ -365,6 +365,8 @@ ClientRequest.prototype.destroy = function destroy(err) {
|
||||
} else if (err) {
|
||||
this[kError] = err;
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
function _destroy(req, socket, err) {
|
||||
|
||||
13
test/parallel/test-client-request-destroy.js
Normal file
13
test/parallel/test-client-request-destroy.js
Normal file
@ -0,0 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
// Test that http.ClientRequest,prototype.destroy() returns `this`.
|
||||
require('../common');
|
||||
|
||||
const assert = require('assert');
|
||||
const http = require('http');
|
||||
const clientRequest = new http.ClientRequest({ createConnection: () => {} });
|
||||
|
||||
assert.strictEqual(clientRequest.destroyed, false);
|
||||
assert.strictEqual(clientRequest.destroy(), clientRequest);
|
||||
assert.strictEqual(clientRequest.destroyed, true);
|
||||
assert.strictEqual(clientRequest.destroy(), clientRequest);
|
||||
Loading…
Reference in New Issue
Block a user