Skip to content

Commit

Permalink
http: return this from IncomingMessage#destroy()
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
cjihrig authored and addaleax committed Sep 22, 2020
1 parent 1b24d3a commit fb68487
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions doc/api/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -1833,9 +1833,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
Expand Down
1 change: 1 addition & 0 deletions lib/_http_incoming.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ IncomingMessage.prototype._read = function _read(n) {
IncomingMessage.prototype.destroy = function destroy(error) {
if (this.socket)
this.socket.destroy(error);
return this;
};


Expand Down
10 changes: 10 additions & 0 deletions test/parallel/test-http-incoming-message-destroy.js
Original file line number Diff line number Diff line change
@@ -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);

0 comments on commit fb68487

Please sign in to comment.