Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http: return this from IncomingMessage#destroy() #32789

Merged
merged 3 commits into from
May 9, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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]>
cjihrig committed May 9, 2020

Verified

This commit was signed with the committer’s verified signature.
cjihrig Colin Ihrig
commit ff6535a4331d611bf0d205ee23d88e100dce92b2
6 changes: 6 additions & 0 deletions doc/api/http.md
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions lib/_http_incoming.js
Original file line number Diff line number Diff line change
@@ -123,6 +123,7 @@ IncomingMessage.prototype.destroy = function destroy(error) {
this.destroyed = true;
if (this.socket)
this.socket.destroy(error);
return this;
};


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