Browse Source

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: https://github.com/nodejs/node/pull/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>
v6
Roee Kasher 8 years ago
committed by Matteo Collina
parent
commit
156549d8ff
  1. 4
      lib/_http_outgoing.js
  2. 15
      test/parallel/test-outgoing-message-pipe.js

4
lib/_http_outgoing.js

@ -889,6 +889,10 @@ OutgoingMessage.prototype.flush = internalUtil.deprecate(function() {
this.flushHeaders(); this.flushHeaders();
}, 'OutgoingMessage.flush is deprecated. Use flushHeaders instead.', 'DEP0001'); }, '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 = { module.exports = {
OutgoingMessage OutgoingMessage

15
test/parallel/test-outgoing-message-pipe.js

@ -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'
);
Loading…
Cancel
Save