Skip to content

Commit

Permalink
chore: do not lazy-load proxy agents
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Jun 1, 2021
1 parent cabacdc commit 1cf6c1f
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions lib/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ const getAuth = u =>

const getPath = u => u.pathname + u.search + u.hash

let HttpProxyAgent
let HttpsProxyAgent
let SocksProxyAgent
const HttpProxyAgent = require('http-proxy-agent')
const HttpsProxyAgent = require('https-proxy-agent')
const SocksProxyAgent = require('socks-proxy-agent')
module.exports.getProxy = getProxy
function getProxy (proxyUrl, opts, isHttps) {
const popts = {
Expand All @@ -177,23 +177,13 @@ function getProxy (proxyUrl, opts, isHttps) {
}

if (proxyUrl.protocol === 'http:' || proxyUrl.protocol === 'https:') {
if (!isHttps) {
if (!HttpProxyAgent)
HttpProxyAgent = require('http-proxy-agent')

if (!isHttps)
return new HttpProxyAgent(popts)
} else {
if (!HttpsProxyAgent)
HttpsProxyAgent = require('https-proxy-agent')

else
return new HttpsProxyAgent(popts)
}
} else if (proxyUrl.protocol.startsWith('socks')) {
if (!SocksProxyAgent)
SocksProxyAgent = require('socks-proxy-agent')

} else if (proxyUrl.protocol.startsWith('socks'))
return new SocksProxyAgent(popts)
} else {
else {
throw Object.assign(
new Error(`unsupported proxy protocol: '${proxyUrl.protocol}'`),
{
Expand Down

0 comments on commit 1cf6c1f

Please sign in to comment.