Skip to content

Commit 340ff98

Browse files
committed
EPMRPP-91841 || HTTPS proxy support for client (#205)
This reverts commit 72695fb.
1 parent b00c5d9 commit 340ff98

File tree

3 files changed

+46
-10
lines changed

3 files changed

+46
-10
lines changed

lib/rest.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const axios = require('axios');
22
const axiosRetry = require('axios-retry').default;
33
const http = require('http');
44
const https = require('https');
5+
const { HttpsProxyAgent } = require('https-proxy-agent');
56
const logger = require('./logger');
67

78
const 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 = /https:?/;
81-
const isHttpsRequest = isHttps.test(protocol);
79+
const { protocol } = new URL(this.baseURL);
80+
const isHttps = /https:?/;
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;

package-lock.json

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

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
"glob": "^8.1.0",
3030
"ini": "^2.0.0",
3131
"uniqid": "^5.4.0",
32-
"uuid": "^9.0.1"
32+
"uuid": "^9.0.1",
33+
"https-proxy-agent": "7.0.4"
3334
},
3435
"license": "Apache-2.0",
3536
"devDependencies": {

0 commit comments

Comments
 (0)