Skip to content
This repository has been archived by the owner on Jun 12, 2022. It is now read-only.

Commit

Permalink
fix(proxy): choose agent for http(s)-proxy by protocol of destUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
yyjdelete authored and zkat committed May 24, 2017
1 parent 563b0d8 commit ea4832a
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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,
Expand All @@ -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) {
Expand Down

0 comments on commit ea4832a

Please sign in to comment.