Skip to content
Merged
Show file tree
Hide file tree
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
Prev Previous commit
http: return this from OutgoingMessage#destroy()
This commit updates OutgoingMessage#destroy() to return `this`
for consistency with other writable streams.

PR-URL: #32789
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
  • Loading branch information
cjihrig committed May 9, 2020
commit 94e5b5c77dade0d8f7358c66144b75c369679cab
4 changes: 3 additions & 1 deletion lib/_http_outgoing.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,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 @@ -294,6 +294,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);