'use strict';vardebug=require('debug')('urllib:detect_proxy_agent');vargetProxyFromURI=require('./get_proxy_from_uri');varproxyAgents={};functiondetectProxyAgent(uri,args){if(!args.enableProxy&&!process.env.URLLIB_ENABLE_PROXY){returnnull;}varproxy=args.proxy||process.env.URLLIB_PROXY;if(!proxy){proxy=getProxyFromURI(uri);if(!proxy){returnnull;}}varproxyAgent=proxyAgents[proxy];if(!proxyAgent){debug('create new proxy %s',proxy);// lazy require, only support node >= 4proxyAgent=proxyAgents[proxy]=new(require('proxy-agent'))(proxy);}debug('get proxy: %s',proxy);returnproxyAgent;}module.exports=detectProxyAgent;module.exports.proxyAgents=proxyAgents;