Skip to content

Commit

Permalink
feat: http and https proxy support
Browse files Browse the repository at this point in the history
  • Loading branch information
kwasniew committed Jul 10, 2024
1 parent 279cd2e commit 8b18442
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
22 changes: 15 additions & 7 deletions src/request.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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 = (
Expand Down
10 changes: 9 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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==
Expand All @@ -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"
Expand Down

0 comments on commit 8b18442

Please sign in to comment.