Skip to content

Commit

Permalink
Make sure emit gets copied over
Browse files Browse the repository at this point in the history
  • Loading branch information
gustav-olsen-groupone committed Mar 4, 2019
1 parent 99c9b7b commit 1d587ca
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/hijackResponse.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ module.exports = function hijackResponse(res, cb) {
var hijackedResponse = new Readable();
hijackedResponse.__proto__ = originalResponse; // eslint-disable-line no-proto

// Reassigning hijackedResponse.emit to itself is necessary to avoid a an never ending loop.
hijackedResponse.emit = hijackedResponse.emit; // eslint-disable-line no-self-assign

var readableMethods = Object.keys(Readable.prototype);

// emit is not included when doing Object.keys on the prototype, but we need
// it.
readableMethods.push("emit");

readableMethods.forEach(function(method) {
hijackedResponse[method] = Readable.prototype[method].bind(
hijackedResponse
Expand Down

0 comments on commit 1d587ca

Please sign in to comment.