feat: Refactor proxy configuration to use getRequestProxyAgents method across multiple modules

This commit is contained in:
Simon Larsen
2025-09-02 14:02:40 +01:00
parent 82065c20b1
commit 0ecdc775db
9 changed files with 34 additions and 44 deletions

View File

@@ -44,10 +44,7 @@ router.get(
requestBody,
{},
undefined,
{
httpAgent: ProxyConfig.getHttpProxyAgent() || undefined,
httpsAgent: ProxyConfig.getHttpsProxyAgent() || undefined,
},
{ ...ProxyConfig.getRequestProxyAgents() },
);
if (result instanceof HTTPErrorResponse) {

View File

@@ -40,10 +40,7 @@ const InitJob: VoidFunction = (): void => {
URL.fromString(PROBE_INGEST_URL.toString()).addRoute("/alive"),
ProbeAPIRequest.getDefaultRequestBody(),
undefined,
{
httpAgent: ProxyConfig.getHttpProxyAgent() || undefined,
httpsAgent: ProxyConfig.getHttpsProxyAgent() || undefined,
},
{ ...ProxyConfig.getRequestProxyAgents() },
);
if (result.isSuccess()) {

View File

@@ -102,10 +102,7 @@ class FetchListAndProbe {
},
{},
{},
{
httpAgent: ProxyConfig.getHttpProxyAgent() || undefined,
httpsAgent: ProxyConfig.getHttpsProxyAgent() || undefined,
},
{ ...ProxyConfig.getRequestProxyAgents() },
);
logger.debug("Fetched monitor list");

View File

@@ -66,10 +66,7 @@ class FetchMonitorTestAndProbe {
},
{},
{},
{
httpAgent: ProxyConfig.getHttpProxyAgent() || undefined,
httpsAgent: ProxyConfig.getHttpsProxyAgent() || undefined,
},
{ ...ProxyConfig.getRequestProxyAgents() },
);
logger.debug("MONITOR TEST: Fetched monitor test list");

View File

@@ -84,10 +84,7 @@ export default class Register {
},
{},
{},
{
httpAgent: ProxyConfig.getHttpProxyAgent() || undefined,
httpsAgent: ProxyConfig.getHttpsProxyAgent() || undefined,
},
{ ...ProxyConfig.getRequestProxyAgents() },
);
}
}
@@ -136,10 +133,7 @@ export default class Register {
clusterKey: ClusterKeyAuthorization.getClusterKey(),
},
undefined,
{
httpAgent: ProxyConfig.getHttpProxyAgent() || undefined,
httpsAgent: ProxyConfig.getHttpsProxyAgent() || undefined,
},
{ ...ProxyConfig.getRequestProxyAgents() },
);
if (result.isSuccess()) {
@@ -164,10 +158,7 @@ export default class Register {
probeId: PROBE_ID.toString(),
},
undefined,
{
httpAgent: ProxyConfig.getHttpProxyAgent() || undefined,
httpsAgent: ProxyConfig.getHttpsProxyAgent() || undefined,
},
{ ...ProxyConfig.getRequestProxyAgents() },
);
LocalCache.setString("PROBE", "PROBE_ID", PROBE_ID.toString() as string);

View File

@@ -75,10 +75,7 @@ export default class MonitorUtil {
},
{},
{},
{
httpAgent: ProxyConfig.getHttpProxyAgent() || undefined,
httpsAgent: ProxyConfig.getHttpsProxyAgent() || undefined,
},
{ ...ProxyConfig.getRequestProxyAgents() },
);
}
@@ -128,10 +125,7 @@ export default class MonitorUtil {
},
{},
{},
{
httpAgent: ProxyConfig.getHttpProxyAgent() || undefined,
httpsAgent: ProxyConfig.getHttpsProxyAgent() || undefined,
},
{ ...ProxyConfig.getRequestProxyAgents() },
);
}

View File

@@ -70,8 +70,7 @@ export default class ApiMonitor {
{
timeout: options.timeout?.toNumber() || 5000,
doNotFollowRedirects: options.doNotFollowRedirects || false,
httpAgent: ProxyConfig.getHttpProxyAgent() || undefined,
httpsAgent: ProxyConfig.getHttpsProxyAgent() || undefined,
...ProxyConfig.getRequestProxyAgents(),
},
);
@@ -90,8 +89,7 @@ export default class ApiMonitor {
{
timeout: options.timeout?.toNumber() || 5000,
doNotFollowRedirects: options.doNotFollowRedirects || false,
httpAgent: ProxyConfig.getHttpProxyAgent() || undefined,
httpsAgent: ProxyConfig.getHttpsProxyAgent() || undefined,
...ProxyConfig.getRequestProxyAgents(),
},
);
}

View File

@@ -65,8 +65,7 @@ export default class WebsiteMonitor {
isHeadRequest: options.isHeadRequest,
timeout: options.timeout?.toNumber() || 5000,
doNotFollowRedirects: options.doNotFollowRedirects || false,
httpAgent: ProxyConfig.getHttpProxyAgent() || undefined,
httpsAgent: ProxyConfig.getHttpsProxyAgent() || undefined,
...ProxyConfig.getRequestProxyAgents(),
});
if (
@@ -79,8 +78,7 @@ export default class WebsiteMonitor {
isHeadRequest: false,
timeout: options.timeout?.toNumber() || 5000,
doNotFollowRedirects: options.doNotFollowRedirects || false,
httpAgent: ProxyConfig.getHttpProxyAgent() || undefined,
httpsAgent: ProxyConfig.getHttpsProxyAgent() || undefined,
...ProxyConfig.getRequestProxyAgents(),
});
}

View File

@@ -73,4 +73,25 @@ export default class ProxyConfig {
return this.httpsProxyAgent;
}
/**
* Returns an object containing httpAgent / httpsAgent suitable to spread into RequestOptions
* or as part of WebsiteRequest.fetch options. If no proxy configured returns empty object.
*/
public static getRequestProxyAgents(): {
httpAgent?: HttpProxyAgent<string>;
httpsAgent?: HttpsProxyAgent<string>;
} {
if (!this.isProxyConfigured()) {
return {};
}
const agents: { httpAgent?: any; httpsAgent?: any } = {};
if (this.httpProxyAgent) {
agents.httpAgent = this.httpProxyAgent;
}
if (this.httpsProxyAgent) {
agents.httpsAgent = this.httpsProxyAgent;
}
return agents;
}
}