diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js index 4357647690beb8..6e1888c6f6dd12 100644 --- a/lib/_http_outgoing.js +++ b/lib/_http_outgoing.js @@ -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; @@ -290,6 +290,8 @@ OutgoingMessage.prototype.destroy = function destroy(error) { socket.destroy(error); }); } + + return this; }; diff --git a/test/parallel/test-outgoing-message-destroy.js b/test/parallel/test-outgoing-message-destroy.js new file mode 100644 index 00000000000000..0ee7b5f40ef9fa --- /dev/null +++ b/test/parallel/test-outgoing-message-destroy.js @@ -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);