Skip to content

Commit fb68487

Browse files
cjihrigaddaleax
authored andcommitted
http: return this from IncomingMessage#destroy()
This commit updates IncomingMessage#destroy() to return `this` for consistency with other readable streams. PR-URL: #32789 Fixes: #32772 Reviewed-By: Robert Nagy <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent 1b24d3a commit fb68487

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

doc/api/http.md

+6
Original file line numberDiff line numberDiff line change
@@ -1833,9 +1833,15 @@ const req = http.request({
18331833
### `message.destroy([error])`
18341834
<!-- YAML
18351835
added: v0.3.0
1836+
changes:
1837+
- version: REPLACEME
1838+
pr-url: https://github.com/nodejs/node/pull/32789
1839+
description: The function returns `this` for consistency with other Readable
1840+
streams.
18361841
-->
18371842

18381843
* `error` {Error}
1844+
* Returns: {this}
18391845

18401846
Calls `destroy()` on the socket that received the `IncomingMessage`. If `error`
18411847
is provided, an `'error'` event is emitted on the socket and `error` is passed

lib/_http_incoming.js

+1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ IncomingMessage.prototype._read = function _read(n) {
114114
IncomingMessage.prototype.destroy = function destroy(error) {
115115
if (this.socket)
116116
this.socket.destroy(error);
117+
return this;
117118
};
118119

119120

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
'use strict';
2+
3+
// Test that http.IncomingMessage,prototype.destroy() returns `this`.
4+
require('../common');
5+
6+
const assert = require('assert');
7+
const http = require('http');
8+
const incomingMessage = new http.IncomingMessage();
9+
10+
assert.strictEqual(incomingMessage.destroy(), incomingMessage);

0 commit comments

Comments
 (0)