@@ -15,56 +15,55 @@ export interface CliHttpClientOptions extends AxiosRequestConfig, Record<string,
1515
1616export class CliHttpClient extends CliHttpLogClient {
1717 protected cliProxyAgent = inject ( CliProxyAgent ) ;
18-
1918 protected host : string ;
19+ private proxySettingsInitialized = false ;
20+ private proxySettingsPromise ?: Promise < void > ;
2021
2122 static getParamsSerializer ( params : any ) {
2223 return stringify ( cleanObject ( params ) ) ;
2324 }
2425
25- async $afterInit ( ) {
26- await this . cliProxyAgent . resolveProxySettings ( ) ;
27- }
28-
2926 async head < T = Record < string , any > > ( endpoint : string , options : CliHttpClientOptions = { } ) : Promise < T > {
30- const { headers} = await axios ( this . getRequestParameters ( "HEAD" , endpoint , options ) ) ;
27+ const { headers} = await axios ( await this . getRequestParameters ( "HEAD" , endpoint , options ) ) ;
3128
3229 return headers as any ;
3330 }
3431
3532 async get < T = unknown > ( endpoint : string , options : CliHttpClientOptions = { } ) : Promise < T > {
36- const result = await this . send ( this . getRequestParameters ( "GET" , endpoint , options ) ) ;
33+ const result = await this . send ( await this . getRequestParameters ( "GET" , endpoint , options ) ) ;
3734
3835 return this . mapResponse ( result , options ) ;
3936 }
4037
4138 async post < T = unknown > ( endpoint : string , options : CliHttpClientOptions = { } ) : Promise < T > {
42- const result = await this . send ( this . getRequestParameters ( "POST" , endpoint , options ) ) ;
39+ const result = await this . send ( await this . getRequestParameters ( "POST" , endpoint , options ) ) ;
4340
4441 return this . mapResponse ( result , options ) ;
4542 }
4643
4744 async put < T = any > ( endpoint : string , options : CliHttpClientOptions = { } ) : Promise < T > {
48- const result = await this . send ( this . getRequestParameters ( "PUT" , endpoint , options ) ) ;
45+ const result = await this . send ( await this . getRequestParameters ( "PUT" , endpoint , options ) ) ;
4946
5047 return this . mapResponse ( result , options ) ;
5148 }
5249
5350 async patch < T = any > ( endpoint : string , options : CliHttpClientOptions = { } ) : Promise < T > {
54- const result = await this . send ( this . getRequestParameters ( "PATCH" , endpoint , options ) ) ;
51+ const result = await this . send ( await this . getRequestParameters ( "PATCH" , endpoint , options ) ) ;
5552
5653 return this . mapResponse ( result , options ) ;
5754 }
5855
5956 async delete < T = any > ( endpoint : string , options : CliHttpClientOptions = { } ) : Promise < T > {
60- const result = await this . send ( this . getRequestParameters ( "DELETE" , endpoint , options ) ) ;
57+ const result = await this . send ( await this . getRequestParameters ( "DELETE" , endpoint , options ) ) ;
6158
6259 return this . mapResponse ( result , options ) ;
6360 }
6461
65- protected getRequestParameters ( method : Method , endpoint : string , options : CliHttpClientOptions ) {
62+ protected async getRequestParameters ( method : Method , endpoint : string , options : CliHttpClientOptions ) {
6663 const url = ( this . host || "" ) + endpoint . replace ( this . host || "" , "" ) ;
6764
65+ await this . resolveProxySettingsOnce ( ) ;
66+
6867 options = {
6968 method,
7069 ...options ,
@@ -78,23 +77,42 @@ export class CliHttpClient extends CliHttpLogClient {
7877 }
7978 } ;
8079
81- this . configureProxy ( url , options ) ;
80+ await this . configureProxy ( url , options ) ;
8281
8382 return options ;
8483 }
8584
86- protected configureProxy ( endpoint : string , options : CliHttpClientOptions ) {
85+ private async resolveProxySettingsOnce ( ) {
86+ if ( this . proxySettingsInitialized ) {
87+ return ;
88+ }
89+
90+ if ( ! this . proxySettingsPromise ) {
91+ this . proxySettingsPromise = this . cliProxyAgent
92+ . resolveProxySettings ( )
93+ . catch ( ( ) => {
94+ return ;
95+ } )
96+ . finally ( ( ) => {
97+ this . proxySettingsInitialized = true ;
98+ } ) ;
99+ }
100+
101+ await this . proxySettingsPromise ;
102+ }
103+
104+ protected async configureProxy ( endpoint : string , options : CliHttpClientOptions ) {
87105 const url = new URL ( endpoint ) ;
88106
89107 if ( this . cliProxyAgent . hasProxy ( ) ) {
90108 const protocol = url . protocol . replace ( ":" , "" ) ;
91109 switch ( protocol ) {
92110 case "https" :
93- options . httpsAgent = this . cliProxyAgent . get ( protocol ) ;
111+ options . httpsAgent = await this . cliProxyAgent . get ( protocol ) ;
94112 options . proxy = false ;
95113 break ;
96114 case "http" :
97- options . httpAgent = this . cliProxyAgent . get ( protocol ) ;
115+ options . httpAgent = await this . cliProxyAgent . get ( protocol ) ;
98116 options . proxy = false ;
99117 break ;
100118 default :
0 commit comments