Skip to content

Commit c795955

Browse files
cjihrigcodebytere
authored andcommittedJun 27, 2020
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 ec01867 commit c795955

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
@@ -1875,9 +1875,15 @@ const req = http.request({
18751875
### `message.destroy([error])`
18761876
<!-- YAML
18771877
added: v0.3.0
1878+
changes:
1879+
- version: REPLACEME
1880+
pr-url: https://github.com/nodejs/node/pull/32789
1881+
description: The function returns `this` for consistency with other Readable
1882+
streams.
18781883
-->
18791884

18801885
* `error` {Error}
1886+
* Returns: {this}
18811887

18821888
Calls `destroy()` on the socket that received the `IncomingMessage`. If `error`
18831889
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
@@ -123,6 +123,7 @@ IncomingMessage.prototype.destroy = function destroy(error) {
123123
this.destroyed = true;
124124
if (this.socket)
125125
this.socket.destroy(error);
126+
return this;
126127
};
127128

128129

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)