From ea4832acdc669ae5f58a6eb3837952969c4d9b56 Mon Sep 17 00:00:00 2001 From: SilverFox Date: Wed, 24 May 2017 08:03:51 +0800 Subject: [PATCH] fix(proxy): choose agent for http(s)-proxy by protocol of destUrl --- agent.js | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/agent.js b/agent.js index fb97208..dc9700c 100644 --- a/agent.js +++ b/agent.js @@ -34,7 +34,7 @@ function getAgent (uri, opts) { } if (pxuri) { - const proxy = getProxy(pxuri, opts) + const proxy = getProxy(pxuri, opts, isHttps) AGENT_CACHE.set(key, proxy) return proxy } @@ -120,7 +120,7 @@ function getProxyUri (uri, opts) { let HttpProxyAgent let HttpsProxyAgent let SocksProxyAgent -function getProxy (proxyUrl, opts) { +function getProxy (proxyUrl, opts, isHttps) { let popts = { host: proxyUrl.hostname, port: proxyUrl.port, @@ -134,19 +134,20 @@ function getProxy (proxyUrl, opts) { rejectUnauthorized: opts.strictSSL } - if (proxyUrl.protocol === 'http:') { - if (!HttpProxyAgent) { - HttpProxyAgent = require('http-proxy-agent') - } + if (proxyUrl.protocol === 'http:' || proxyUrl.protocol === 'https:') { + if (!isHttps) { + if (!HttpProxyAgent) { + HttpProxyAgent = require('http-proxy-agent') + } - return new HttpProxyAgent(popts) - } - if (proxyUrl.protocol === 'https:') { - if (!HttpsProxyAgent) { - HttpsProxyAgent = require('https-proxy-agent') - } + return new HttpProxyAgent(popts) + } else { + if (!HttpsProxyAgent) { + HttpsProxyAgent = require('https-proxy-agent') + } - return new HttpsProxyAgent(popts) + return new HttpsProxyAgent(popts) + } } if (proxyUrl.startsWith('socks')) { if (!SocksProxyAgent) {