Skip to content
This repository has been archived by the owner on May 5, 2023. It is now read-only.

Commit

Permalink
Fix Node 12
Browse files Browse the repository at this point in the history
  • Loading branch information
TooTallNate committed Dec 10, 2019
1 parent 308d1df commit 6884fed
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
9 changes: 9 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,21 @@ HttpProxyAgent.prototype.callback = function connect (req, opts, fn) {
req._header = null;
req._implicitHeader();
if (req.output && req.output.length > 0) {
// Node < 12
debug('patching connection write() output buffer with updated header');
// the _header has already been queued to be written to the socket
var first = req.output[0];
var endOfHeaders = first.indexOf('\r\n\r\n') + 4;
req.output[0] = req._header + first.substring(endOfHeaders);
debug('output buffer: %o', req.output);
} else if (req.outputData && req.outputData.length > 0) {
// Node >= 12
debug('patching connection write() output buffer with updated header');
var first = req.outputData[0].data;
// the _header has already been queued to be written to the socket
var endOfHeaders = first.indexOf('\r\n\r\n') + 4;
req.outputData[0].data = req._header + first.substring(endOfHeaders);
debug('output buffer: %o', req.outputData[0].data);
}
}

Expand Down
4 changes: 4 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ describe('HttpProxyAgent', function () {
});
});

beforeEach(function () {
server.removeAllListeners('request');
});

before(function (done) {
// setup SSL HTTP proxy server
var options = {
Expand Down

0 comments on commit 6884fed

Please sign in to comment.