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:
cjihrig
2020-04-11 16:06:43 -04:00
parent ae34e4737a
commit ff6535a433
3 changed files with 17 additions and 0 deletions

View File

@@ -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

View File

@@ -123,6 +123,7 @@ IncomingMessage.prototype.destroy = function destroy(error) {
this.destroyed = true;
if (this.socket)
this.socket.destroy(error);
return this;
};

View 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);