diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js index 1c570284ef5ccb..7a63406d51575b 100644 --- a/lib/_http_outgoing.js +++ b/lib/_http_outgoing.js @@ -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 diff --git a/test/parallel/test-outgoing-message-pipe.js b/test/parallel/test-outgoing-message-pipe.js new file mode 100644 index 00000000000000..2030d8f43b09be --- /dev/null +++ b/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' +);