diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js index 33520610bc0eb2..2e639535ee4a9e 100644 --- a/lib/_http_outgoing.js +++ b/lib/_http_outgoing.js @@ -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; @@ -294,6 +294,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);