mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
http: return this from IncomingMessage#destroy()
This commit updates IncomingMessage#destroy() to return `this` for consistency with other readable streams. PR-URL: https://github.com/nodejs/node/pull/32789 Fixes: https://github.com/nodejs/node/issues/32772 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:
@@ -1847,9 +1847,15 @@ const req = http.request({
|
||||
### `message.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}
|
||||
* Returns: {this}
|
||||
|
||||
Calls `destroy()` on the socket that received the `IncomingMessage`. If `error`
|
||||
is provided, an `'error'` event is emitted on the socket and `error` is passed
|
||||
|
||||
@@ -123,6 +123,7 @@ IncomingMessage.prototype.destroy = function destroy(error) {
|
||||
this.destroyed = true;
|
||||
if (this.socket)
|
||||
this.socket.destroy(error);
|
||||
return this;
|
||||
};
|
||||
|
||||
|
||||
|
||||
10
test/parallel/test-http-incoming-message-destroy.js
Normal file
10
test/parallel/test-http-incoming-message-destroy.js
Normal file
@@ -0,0 +1,10 @@
|
||||
'use strict';
|
||||
|
||||
// Test that http.IncomingMessage,prototype.destroy() returns `this`.
|
||||
require('../common');
|
||||
|
||||
const assert = require('assert');
|
||||
const http = require('http');
|
||||
const incomingMessage = new http.IncomingMessage();
|
||||
|
||||
assert.strictEqual(incomingMessage.destroy(), incomingMessage);
|
||||
Reference in New Issue
Block a user