diff --git a/package.json b/package.json index 48346a01..7e351761 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,8 @@ "dependencies": { "ip-address": "^9.0.5", "make-fetch-happen": "^13.0.1", + "http-proxy-agent": "^7.0.2", + "https-proxy-agent": "^7.0.5", "murmurhash3js": "^3.0.1", "semver": "^7.6.2" }, diff --git a/src/request.ts b/src/request.ts index f3350f89..dd609767 100644 --- a/src/request.ts +++ b/src/request.ts @@ -1,4 +1,6 @@ import * as fetch from 'make-fetch-happen'; +import { HttpProxyAgent } from 'http-proxy-agent'; +import { HttpsProxyAgent } from 'https-proxy-agent'; import * as http from 'http'; import * as https from 'https'; import { URL } from 'url'; @@ -29,17 +31,23 @@ export interface PostRequestOptions extends RequestOptions { instanceId?: string; httpOptions?: HttpOptions; } -const httpAgent = new http.Agent({ - keepAlive: true, - keepAliveMsecs: 30 * 1000, - timeout: 10 * 1000, -}); -const httpsAgent = new https.Agent({ +const httpProxy = process.env.HTTP_PROXY || process.env.http_proxy; +const httpsProxy = process.env.HTTPS_PROXY || process.env.https_proxy; + +const httpAgentOptions: http.AgentOptions = { keepAlive: true, keepAliveMsecs: 30 * 1000, timeout: 10 * 1000, -}); +}; + +const httpAgent = httpProxy + ? new HttpProxyAgent(httpProxy, httpAgentOptions) + : new http.Agent(httpAgentOptions); + +const httpsAgent = httpsProxy + ? new HttpsProxyAgent(httpsProxy, httpAgentOptions) + : new https.Agent(httpAgentOptions); export const getDefaultAgent = (url: URL) => (url.protocol === 'https:' ? httpsAgent : httpAgent); export const buildHeaders = ( diff --git a/yarn.lock b/yarn.lock index 02c46d07..51534c64 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2723,7 +2723,7 @@ http-cache-semantics@^4.1.1: resolved "https://registry.yarnpkg.com/http-cache-semantics/-/http-cache-semantics-4.1.1.tgz#abe02fcb2985460bf0323be664436ec3476a6d5a" integrity sha512-er295DKPVsV82j5kw1Gjt+ADA/XYHsajl82cGNQG2eyoPkvgUhX+nDIyelzhIWbbsXP39EHcI6l5tYs2FYqYXQ== -http-proxy-agent@^7.0.0: +http-proxy-agent@^7.0.0, http-proxy-agent@^7.0.2: version "7.0.2" resolved "https://registry.yarnpkg.com/http-proxy-agent/-/http-proxy-agent-7.0.2.tgz#9a8b1f246866c028509486585f62b8f2c18c270e" integrity sha512-T1gkAiYYDWYx3V5Bmyu7HcfcvL7mUrTWiM6yOfa3PIphViJ/gFPbvidQ+veqSOHci/PxBcDabeUNCzpOODJZig== @@ -2748,6 +2748,14 @@ https-proxy-agent@^7.0.1: agent-base "^7.0.2" debug "4" +https-proxy-agent@^7.0.5: + version "7.0.5" + resolved "https://registry.yarnpkg.com/https-proxy-agent/-/https-proxy-agent-7.0.5.tgz#9e8b5013873299e11fab6fd548405da2d6c602b2" + integrity sha512-1e4Wqeblerz+tMKPIq2EMGiiWW1dIjZOksyHWSUm1rmuvw/how9hBHZ38lAGj5ID4Ik6EdkOw7NmWPy6LAwalw== + dependencies: + agent-base "^7.0.2" + debug "4" + human-signals@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/human-signals/-/human-signals-2.1.0.tgz#dc91fcba42e4d06e4abaed33b3e7a3c02f514ea0"