Skip to content

Commit

Permalink
EPMRPP-91841 || HTTPS proxy support for client (#205)
Browse files Browse the repository at this point in the history
This reverts commit 72695fb.
  • Loading branch information
AmsterGet committed Sep 17, 2024
1 parent b00c5d9 commit 340ff98
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 10 deletions.
25 changes: 19 additions & 6 deletions lib/rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const axios = require('axios');
const axiosRetry = require('axios-retry').default;
const http = require('http');
const https = require('https');
const { HttpsProxyAgent } = require('https-proxy-agent');
const logger = require('./logger');

const DEFAULT_MAX_CONNECTION_TIME_MS = 30000;
Expand Down Expand Up @@ -75,13 +76,25 @@ method: ${method}`,
return acc;
}, {});

if ('agent' in this.restClientConfig) {
const { protocol } = new URL(this.baseURL);
const isHttps = /https:?/;
const isHttpsRequest = isHttps.test(protocol);
const { protocol } = new URL(this.baseURL);
const isHttps = /https:?/;
const isHttpsRequest = isHttps.test(protocol);
const agentOptions = this.restClientConfig.agent;

if (agentOptions) {
config[isHttpsRequest ? 'httpsAgent' : 'httpAgent'] = isHttpsRequest
? new https.Agent(this.restClientConfig.agent)
: new http.Agent(this.restClientConfig.agent);
? new https.Agent(agentOptions)
: new http.Agent(agentOptions);
}

if (config.proxy && isHttpsRequest) {
const { auth, protocol: proxyProtocol, host, port } = config.proxy;
const authString = auth ? `${auth.username}:${auth.password}@` : '';
const proxyUrl = `${proxyProtocol}://${authString}${host}:${port}`;

config.httpsAgent = new HttpsProxyAgent(proxyUrl, agentOptions);

config.proxy = false;
}

return config;
Expand Down
28 changes: 25 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"glob": "^8.1.0",
"ini": "^2.0.0",
"uniqid": "^5.4.0",
"uuid": "^9.0.1"
"uuid": "^9.0.1",
"https-proxy-agent": "7.0.4"
},
"license": "Apache-2.0",
"devDependencies": {
Expand Down

0 comments on commit 340ff98

Please sign in to comment.