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 <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 authored and codebytere committed Jun 27, 2020
1 parent d87031d commit e1e3ae1
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 e1e3ae1

Please sign in to comment.