From 46aad0988b471f042856436cf3192b0e09e36fe6 Mon Sep 17 00:00:00 2001 From: Luigi Pinca Date: Fri, 26 Jul 2019 16:30:23 +0200 Subject: [PATCH] Remove unreachable code Node.js < 4.5.0 is no longer supported as per https://github.com/TooTallNate/node-https-proxy-agent/commit/a2779222. --- index.js | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/index.js b/index.js index 0a2fdabe..72936452 100644 --- a/index.js +++ b/index.js @@ -91,7 +91,6 @@ HttpsProxyAgent.prototype.callback = function connect(req, opts, fn) { } function cleanup() { - socket.removeListener('data', ondata); socket.removeListener('end', onend); socket.removeListener('error', onerror); socket.removeListener('close', onclose); @@ -120,11 +119,7 @@ HttpsProxyAgent.prototype.callback = function connect(req, opts, fn) { if (!~str.indexOf('\r\n\r\n')) { // keep buffering debug('have not received end of HTTP headers yet...'); - if (socket.read) { - read(); - } else { - socket.once('data', ondata); - } + read(); return; } @@ -174,11 +169,7 @@ HttpsProxyAgent.prototype.callback = function connect(req, opts, fn) { function onsocket(socket) { // replay the "buffers" Buffer onto the `socket`, since at this point // the HTTP module machinery has been hooked up for the user - if ('function' == typeof socket.ondata) { - // node <= v0.11.3, the `ondata` function is set on the socket - socket.ondata(buffers, 0, buffers.length); - } else if (socket.listeners('data').length > 0) { - // node > v0.11.3, the "data" event is listened for directly + if (socket.listenerCount('data') > 0) { socket.emit('data', buffers); } else { // never? @@ -193,11 +184,7 @@ HttpsProxyAgent.prototype.callback = function connect(req, opts, fn) { socket.on('close', onclose); socket.on('end', onend); - if (socket.read) { - read(); - } else { - socket.once('data', ondata); - } + read(); var hostname = opts.host + ':' + opts.port; var msg = 'CONNECT ' + hostname + ' HTTP/1.1\r\n';