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

Commit 6884fed

Browse files
committed
Fix Node 12
1 parent 308d1df commit 6884fed

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,21 @@ HttpProxyAgent.prototype.callback = function connect (req, opts, fn) {
9898
req._header = null;
9999
req._implicitHeader();
100100
if (req.output && req.output.length > 0) {
101+
// Node < 12
101102
debug('patching connection write() output buffer with updated header');
102103
// the _header has already been queued to be written to the socket
103104
var first = req.output[0];
104105
var endOfHeaders = first.indexOf('\r\n\r\n') + 4;
105106
req.output[0] = req._header + first.substring(endOfHeaders);
106107
debug('output buffer: %o', req.output);
108+
} else if (req.outputData && req.outputData.length > 0) {
109+
// Node >= 12
110+
debug('patching connection write() output buffer with updated header');
111+
var first = req.outputData[0].data;
112+
// the _header has already been queued to be written to the socket
113+
var endOfHeaders = first.indexOf('\r\n\r\n') + 4;
114+
req.outputData[0].data = req._header + first.substring(endOfHeaders);
115+
debug('output buffer: %o', req.outputData[0].data);
107116
}
108117
}
109118

test/test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ describe('HttpProxyAgent', function () {
4040
});
4141
});
4242

43+
beforeEach(function () {
44+
server.removeAllListeners('request');
45+
});
46+
4347
before(function (done) {
4448
// setup SSL HTTP proxy server
4549
var options = {

0 commit comments

Comments
 (0)