Skip to content

Commit c99fdb8

Browse files
authored
Merge pull request #62 from CheckmarxDev/bug/miryamFoifer/proxyAgent3
fix issue to download CLI due to PROXY
2 parents 265ac11 + a4e9ec7 commit c99fdb8

File tree

3 files changed

+57
-29
lines changed

3 files changed

+57
-29
lines changed

package-lock.json

Lines changed: 44 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"dependencies": {
1313
"async-mutex": "^0.5.0",
1414
"axios": "^1.7.7",
15+
"https-proxy-agent": "^7.0.6",
1516
"log4js": "^6.9.1",
1617
"node-fetch": "^3.3.2",
1718
"tar": "^7.4.3",

src/main/client/HttpClient.ts

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
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

56
export 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

Comments
 (0)