Skip to content

Commit

Permalink
http: disable OutgoingMessage pipe method
Browse files Browse the repository at this point in the history
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 <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
  • Loading branch information
Kasher authored and mcollina committed Jul 25, 2017
1 parent c49adbf commit 156549d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/_http_outgoing.js
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,10 @@ OutgoingMessage.prototype.flush = internalUtil.deprecate(function() {
this.flushHeaders();
}, 'OutgoingMessage.flush is deprecated. Use flushHeaders instead.', 'DEP0001');

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

module.exports = {
OutgoingMessage
Expand Down
15 changes: 15 additions & 0 deletions test/parallel/test-outgoing-message-pipe.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict';
const assert = require('assert');
const common = require('../common');
const OutgoingMessage = require('_http_outgoing').OutgoingMessage;

// Verify that an error is thrown upon a call to `OutgoingMessage.pipe`.

const outgoingMessage = new OutgoingMessage();
assert.throws(
common.mustCall(() => { outgoingMessage.pipe(outgoingMessage); }),
(err) => {
return ((err instanceof Error) && /Cannot pipe, not readable/.test(err));
},
'OutgoingMessage.pipe should throw an error'
);

0 comments on commit 156549d

Please sign in to comment.