You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							32 lines
						
					
					
						
							786 B
						
					
					
				
			
		
		
	
	
							32 lines
						
					
					
						
							786 B
						
					
					
				| 'use strict';
 | |
| 
 | |
| var debug = require('debug')('urllib:detect_proxy_agent');
 | |
| var getProxyFromURI = require('./get_proxy_from_uri');
 | |
| 
 | |
| var proxyAgents = {};
 | |
| 
 | |
| function detectProxyAgent(uri, args) {
 | |
|   if (!args.enableProxy && !process.env.URLLIB_ENABLE_PROXY) {
 | |
|     return null;
 | |
|   }
 | |
|   var proxy = args.proxy || process.env.URLLIB_PROXY;
 | |
|   if (!proxy) {
 | |
|     proxy = getProxyFromURI(uri);
 | |
|     if (!proxy) {
 | |
|       return null;
 | |
|     }
 | |
|   }
 | |
| 
 | |
|   var proxyAgent = proxyAgents[proxy];
 | |
|   if (!proxyAgent) {
 | |
|     debug('create new proxy %s', proxy);
 | |
|     // lazy require, only support node >= 4
 | |
|     proxyAgent = proxyAgents[proxy] = new (require('proxy-agent'))(proxy);
 | |
|   }
 | |
|   debug('get proxy: %s', proxy);
 | |
|   return proxyAgent;
 | |
| }
 | |
| 
 | |
| module.exports = detectProxyAgent;
 | |
| module.exports.proxyAgents = proxyAgents;
 |