more reliable setup of proxy agent
Some checks failed
test / lint-and-spellcheck (push) Has been cancelled
test / unit-tests (18.x) (push) Has been cancelled
test / unit-tests (20.x) (push) Has been cancelled
test / unit-tests (22.x) (push) Has been cancelled
test / integration-tests (18.x) (push) Has been cancelled
test / integration-tests (20.x) (push) Has been cancelled
test / integration-tests (22.x) (push) Has been cancelled
test / e2e-tests (18.x) (push) Has been cancelled

This commit is contained in:
Traines 2025-03-08 23:12:36 +00:00
parent 960371e2ec
commit 9975a6c9ac

View file

@ -7,15 +7,16 @@ const proxyAddress = typeof process !== 'undefined' && (process.env.HTTPS_PROXY
let getAgent = () => undefined;
if (proxyAddress) {
import('https-proxy-agent').then(a => {
const setupProxy = async () => {
if (proxyAddress && !getAgent()) {
const a = await import('https-proxy-agent');
const agent = new a.default.HttpsProxyAgent(proxyAddress, {
keepAlive: true,
keepAliveMsecs: 10 * 1000, // 10s
});
getAgent = () => agent;
});
}
}
};
const randomBytesHexString = length => [...Array(length)].map(() => Math.floor(Math.random() * 16)
.toString(16))
@ -74,6 +75,7 @@ const checkIfResponseIsOk = (_) => {
const request = async (ctx, userAgent, reqData) => {
const {profile, opt} = ctx;
await setupProxy();
const endpoint = reqData.endpoint;
delete reqData.endpoint;