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 codebytere committed Jun 27, 2020
1 parent ec01867 commit c795955
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 @@ -1875,9 +1875,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 @@ -123,6 +123,7 @@ IncomingMessage.prototype.destroy = function destroy(error) {
this.destroyed = true;
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 c795955

Please sign in to comment.