Skip to content

Commit ec7c3ec

Browse files
committed
Fix compatibility with Node.js >= 10.0.0
Resume the socket after the `'socket'` event is emitted on the `ClientRequest` object. Refs: nodejs/node#24474 (comment) Fixes: TooTallNate#58
1 parent 84daab7 commit ec7c3ec

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

index.js

+13
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ HttpsProxyAgent.prototype.callback = function connect(req, opts, fn) {
150150
}
151151

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

180+
socket.resume();
179181
// nullify the cached Buffer instance
180182
buffers = null;
181183
}
@@ -211,6 +213,17 @@ HttpsProxyAgent.prototype.callback = function connect(req, opts, fn) {
211213
socket.write(msg + '\r\n');
212214
};
213215

216+
/**
217+
* Resumes a socket.
218+
*
219+
* @param {(net.Socket|tls.Socket)} socket The socket to resume
220+
* @api public
221+
*/
222+
223+
function resume(socket) {
224+
socket.resume();
225+
}
226+
214227
function isDefaultPort(port, secure) {
215228
return Boolean((!secure && port === 80) || (secure && port === 443));
216229
}

0 commit comments

Comments
 (0)