Skip to content

Commit 156549d

Browse files
Kashermcollina
authored andcommitted
http: disable OutgoingMessage pipe method
OutgoingMessage should be a write-only stream, and it shouldn't be piped. This commit disables the `pipe` method by throwing an exception (if this method is called). PR-URL: #14358 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Gireesh Punathil <[email protected]>
1 parent c49adbf commit 156549d

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lib/_http_outgoing.js

+4
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,10 @@ OutgoingMessage.prototype.flush = internalUtil.deprecate(function() {
889889
this.flushHeaders();
890890
}, 'OutgoingMessage.flush is deprecated. Use flushHeaders instead.', 'DEP0001');
891891

892+
OutgoingMessage.prototype.pipe = function pipe() {
893+
// OutgoingMessage should be write-only. Piping from it is disabled.
894+
this.emit('error', new Error('Cannot pipe, not readable'));
895+
};
892896

893897
module.exports = {
894898
OutgoingMessage
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'use strict';
2+
const assert = require('assert');
3+
const common = require('../common');
4+
const OutgoingMessage = require('_http_outgoing').OutgoingMessage;
5+
6+
// Verify that an error is thrown upon a call to `OutgoingMessage.pipe`.
7+
8+
const outgoingMessage = new OutgoingMessage();
9+
assert.throws(
10+
common.mustCall(() => { outgoingMessage.pipe(outgoingMessage); }),
11+
(err) => {
12+
return ((err instanceof Error) && /Cannot pipe, not readable/.test(err));
13+
},
14+
'OutgoingMessage.pipe should throw an error'
15+
);

0 commit comments

Comments
 (0)