Skip to content

Commit e1e3ae1

Browse files
cjihrigcodebytere
authored andcommitted
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 <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent d87031d commit e1e3ae1

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/_http_outgoing.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ OutgoingMessage.prototype.setTimeout = function setTimeout(msecs, callback) {
279279
// it, since something else is destroying this connection anyway.
280280
OutgoingMessage.prototype.destroy = function destroy(error) {
281281
if (this.destroyed) {
282-
return;
282+
return this;
283283
}
284284
this.destroyed = true;
285285

@@ -290,6 +290,8 @@ OutgoingMessage.prototype.destroy = function destroy(error) {
290290
socket.destroy(error);
291291
});
292292
}
293+
294+
return this;
293295
};
294296

295297

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use strict';
2+
3+
// Test that http.OutgoingMessage,prototype.destroy() returns `this`.
4+
require('../common');
5+
6+
const assert = require('assert');
7+
const http = require('http');
8+
const outgoingMessage = new http.OutgoingMessage();
9+
10+
assert.strictEqual(outgoingMessage.destroyed, false);
11+
assert.strictEqual(outgoingMessage.destroy(), outgoingMessage);
12+
assert.strictEqual(outgoingMessage.destroyed, true);
13+
assert.strictEqual(outgoingMessage.destroy(), outgoingMessage);

0 commit comments

Comments
 (0)