From 94e5b5c77dade0d8f7358c66144b75c369679cab Mon Sep 17 00:00:00 2001 From: cjihrig Date: Fri, 8 May 2020 21:44:13 -0400 Subject: [PATCH] http: return this from OutgoingMessage#destroy() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit updates OutgoingMessage#destroy() to return `this` for consistency with other writable streams. PR-URL: https://github.com/nodejs/node/pull/32789 Reviewed-By: Robert Nagy Reviewed-By: Anna Henningsen Reviewed-By: Michaƫl Zasso Reviewed-By: Ruben Bridgewater --- lib/_http_outgoing.js | 4 +++- test/parallel/test-outgoing-message-destroy.js | 13 +++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 test/parallel/test-outgoing-message-destroy.js 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);