Skip to content

Commit

Permalink
Fix compatibility with Node.js >= 10.0.0
Browse files Browse the repository at this point in the history
Resume the socket after the `'socket'` event is emitted on the
`ClientRequest` object.

Refs: nodejs/node#24474 (comment)
Fixes: #58
  • Loading branch information
lpinca authored and TooTallNate committed Oct 4, 2019
1 parent 46aad09 commit 2629ba6
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions index.js
Expand Up @@ -150,6 +150,7 @@ HttpsProxyAgent.prototype.callback = function connect(req, opts, fn) {
}

cleanup();
req.once('socket', resume);
fn(null, sock);
} else {
// some other status code that's not 200... need to re-play the HTTP header
Expand All @@ -176,6 +177,7 @@ HttpsProxyAgent.prototype.callback = function connect(req, opts, fn) {
throw new Error('should not happen...');
}

socket.resume();
// nullify the cached Buffer instance
buffers = null;
}
Expand Down Expand Up @@ -211,6 +213,17 @@ HttpsProxyAgent.prototype.callback = function connect(req, opts, fn) {
socket.write(msg + '\r\n');
};

/**
* Resumes a socket.
*
* @param {(net.Socket|tls.Socket)} socket The socket to resume
* @api public
*/

function resume(socket) {
socket.resume();
}

function isDefaultPort(port, secure) {
return Boolean((!secure && port === 80) || (secure && port === 443));
}

0 comments on commit 2629ba6

Please sign in to comment.