@@ -2,6 +2,7 @@ const axios = require('axios');
22const axiosRetry = require ( 'axios-retry' ) . default ;
33const http = require ( 'http' ) ;
44const https = require ( 'https' ) ;
5+ const { HttpsProxyAgent } = require ( 'https-proxy-agent' ) ;
56const logger = require ( './logger' ) ;
67
78const DEFAULT_MAX_CONNECTION_TIME_MS = 30000 ;
@@ -75,13 +76,25 @@ method: ${method}`,
7576 return acc ;
7677 } , { } ) ;
7778
78- if ( 'agent' in this . restClientConfig ) {
79- const { protocol } = new URL ( this . baseURL ) ;
80- const isHttps = / h t t p s : ? / ;
81- const isHttpsRequest = isHttps . test ( protocol ) ;
79+ const { protocol } = new URL ( this . baseURL ) ;
80+ const isHttps = / h t t p s : ? / ;
81+ const isHttpsRequest = isHttps . test ( protocol ) ;
82+ const agentOptions = this . restClientConfig . agent ;
83+
84+ if ( agentOptions ) {
8285 config [ isHttpsRequest ? 'httpsAgent' : 'httpAgent' ] = isHttpsRequest
83- ? new https . Agent ( this . restClientConfig . agent )
84- : new http . Agent ( this . restClientConfig . agent ) ;
86+ ? new https . Agent ( agentOptions )
87+ : new http . Agent ( agentOptions ) ;
88+ }
89+
90+ if ( config . proxy && isHttpsRequest ) {
91+ const { auth, protocol : proxyProtocol , host, port } = config . proxy ;
92+ const authString = auth ? `${ auth . username } :${ auth . password } @` : '' ;
93+ const proxyUrl = `${ proxyProtocol } ://${ authString } ${ host } :${ port } ` ;
94+
95+ config . httpsAgent = new HttpsProxyAgent ( proxyUrl , agentOptions ) ;
96+
97+ config . proxy = false ;
8598 }
8699
87100 return config ;
0 commit comments