@@ -6,10 +6,11 @@ const Q = require('q');
66const url = require ( 'url' ) ;
77const utils = require ( "../utils" ) ;
88const ensureOption = require ( '../utils/ensureOption' ) . defaults ( config ( ) ) ;
9- const ProxyAgent = utils . optionalRequireProxyAgent ( ) ;
109
1110const { extend, includes, isEmpty } = utils ;
1211
12+ const agent = config . api_proxy ? new https . Agent ( config . api_proxy ) : null ;
13+
1314function execute_request ( method , params , auth , api_url , callback , options = { } ) {
1415 method = method . toUpperCase ( ) ;
1516 const deferred = Q . defer ( ) ;
@@ -53,11 +54,10 @@ function execute_request(method, params, auth, api_url, callback, options = {})
5354
5455 let proxy = options . api_proxy || config ( ) . api_proxy ;
5556 if ( ! isEmpty ( proxy ) ) {
56- if ( ! request_options . agent ) {
57- if ( ProxyAgent === null ) {
58- throw new Error ( "Proxy value is set, but `proxy-agent` is not installed, please install `proxy-agent` module." )
59- }
60- request_options . agent = new ProxyAgent ( proxy ) ;
57+ if ( ! request_options . agent && agent ) {
58+ request_options . agent = agent ;
59+ } else if ( ! request_options . agent ) {
60+ request_options . agent = new https . Agent ( proxy ) ;
6161 } else {
6262 console . warn ( "Proxy is set, but request uses a custom agent, proxy is ignored." ) ;
6363 }
0 commit comments