Skip to content

Commit

Permalink
http: return this from OutgoingMessage#destroy()
Browse files Browse the repository at this point in the history
This commit updates OutgoingMessage#destroy() to return `this`
for consistency with other writable streams.

PR-URL: #32789
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 30, 2020
1 parent e76ee87 commit 277b45d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/_http_outgoing.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ OutgoingMessage.prototype.setTimeout = function setTimeout(msecs, callback) {
// it, since something else is destroying this connection anyway.
OutgoingMessage.prototype.destroy = function destroy(error) {
if (this.destroyed) {
return;
return this;
}
this.destroyed = true;

Expand All @@ -290,6 +290,8 @@ OutgoingMessage.prototype.destroy = function destroy(error) {
socket.destroy(error);
});
}

return this;
};


Expand Down
13 changes: 13 additions & 0 deletions test/parallel/test-outgoing-message-destroy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';

// Test that http.OutgoingMessage,prototype.destroy() returns `this`.
require('../common');

const assert = require('assert');
const http = require('http');
const outgoingMessage = new http.OutgoingMessage();

assert.strictEqual(outgoingMessage.destroyed, false);
assert.strictEqual(outgoingMessage.destroy(), outgoingMessage);
assert.strictEqual(outgoingMessage.destroyed, true);
assert.strictEqual(outgoingMessage.destroy(), outgoingMessage);

0 comments on commit 277b45d

Please sign in to comment.