1- import axios , { AxiosRequestConfig , AxiosResponse } from 'axios' ;
2- import { logger } from '../wrapper/loggerConfig' ;
3- import { Client } from "./Client" ;
1+ import axios , { AxiosRequestConfig , AxiosResponse } from 'axios' ;
2+ import { logger } from '../wrapper/loggerConfig' ;
3+ import { Client } from "./Client" ;
4+ import { HttpsProxyAgent } from 'https-proxy-agent' ; // Import as a function
45
56export class HttpClient implements Client {
67 private readonly axiosConfig : AxiosRequestConfig ;
@@ -9,47 +10,35 @@ export class HttpClient implements Client {
910 constructor ( ) {
1011 this . axiosConfig = {
1112 responseType : 'stream' ,
12- proxy : this . getProxyConfig ( ) ,
13+ httpsAgent : this . getProxyConfig ( ) , // Use httpsAgent instead of proxy
1314 } ;
1415 }
1516
1617 public getProxyConfig ( ) {
1718 const proxyUrl = process . env . HTTP_PROXY ;
1819 if ( proxyUrl ) {
1920 logger . info ( `Detected proxy configuration in HTTP_PROXY` ) ;
20- const parsedProxy = new URL ( proxyUrl ) ;
21-
22- return {
23- host : parsedProxy . hostname ,
24- port : parseInt ( parsedProxy . port , 10 ) ,
25- protocol : parsedProxy . protocol . replace ( ':' , '' ) , // remove the colon
26- auth : parsedProxy . username && parsedProxy . password
27- ? { username : parsedProxy . username , password : parsedProxy . password }
28- : undefined ,
29- } ;
21+ return new HttpsProxyAgent ( proxyUrl ) ;
3022 }
3123 logger . info ( 'No proxy configuration detected.' ) ;
3224 return undefined ;
3325 }
34-
26+
3527 public async request ( url : string , method : string , data : any ) : Promise < AxiosResponse < any , any > > {
3628 logger . info ( `Sending ${ method } request to URL: ${ url } ` ) ;
37- if ( this . axiosConfig . proxy ) {
38- logger . info (
39- `Using proxy - Host: ${ this . axiosConfig . proxy . host } , Port: ${ this . axiosConfig . proxy . port } ,` +
40- `Protocol: ${ this . axiosConfig . proxy . protocol } , Auth: ${ this . axiosConfig . proxy . auth ? 'Yes' : 'No' } `
41- ) ;
29+ if ( this . axiosConfig . httpsAgent ) {
30+ logger . info ( `Using proxy - URL: ${ process . env . HTTP_PROXY } ` ) ;
4231 }
4332 try {
44- const response = await axios ( { ...this . axiosConfig , url, method, data} ) ;
33+ const response = await axios ( { ...this . axiosConfig , url, method, data } ) ;
4534 logger . info ( `Request completed successfully.` ) ;
4635 return response ;
4736 } catch ( error ) {
4837 logger . error ( `Error sending ${ method } request to ${ url } : ${ error . message || error } ` ) ;
49- if ( this . axiosConfig . proxy !== undefined ) {
38+ if ( this . axiosConfig . httpsAgent !== undefined ) {
5039 throw new Error ( `${ this . domainErrMsg } \nError: ${ error . message || error } ` ) ;
5140 }
5241 throw error ;
5342 }
5443 }
55- }
44+ }
0 commit comments