Skip to content

Commit 6454b5e

Browse files
committed
Remove HttpsProxyAgent, allow users to pass http.RequestOptions instead
1 parent e986287 commit 6454b5e

File tree

2 files changed

+11
-40
lines changed

2 files changed

+11
-40
lines changed

src/config.ts

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,12 @@
1-
import process from "node:process";
1+
import http from "node:http";
22

33
export type Config = {
44
api_key: string | null;
55
timeout: number;
6-
http_proxy?: string;
7-
https_proxy?: string;
8-
no_proxy?: string;
6+
requestOptions?: http.RequestOptions;
97
};
108

11-
function getEnvVar(name: string): string | undefined {
12-
if (typeof Deno !== "undefined") {
13-
return Deno.env.get(name);
14-
} else if (typeof process !== "undefined") {
15-
return process.env[name];
16-
}
17-
return undefined;
18-
}
19-
209
export const config: Config = {
2110
api_key: null,
2211
timeout: 60000,
23-
http_proxy: getEnvVar("HTTP_PROXY") || getEnvVar("http_proxy"),
24-
https_proxy: getEnvVar("HTTPS_PROXY") || getEnvVar("https_proxy"),
25-
no_proxy: getEnvVar("NO_PROXY") || getEnvVar("no_proxy"),
2612
};

src/utils.ts

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { version } from "../version.ts";
22
import https from "node:https";
33
import http from "node:http";
44
import qs from "node:querystring";
5-
import { HttpsProxyAgent } from "npm:https-proxy-agent";
65
import { RequestTimeoutError } from "./errors.ts";
76
import { config } from "./config.ts";
87
import { Buffer } from "node:buffer";
@@ -43,7 +42,7 @@ export function getSource() {
4342

4443
export function buildUrl(
4544
path: string,
46-
parameters: qs.ParsedUrlQueryInput,
45+
parameters: qs.ParsedUrlQueryInput
4746
): string {
4847
const clonedParams = { ...parameters };
4948
for (const k in clonedParams) {
@@ -57,23 +56,13 @@ export function buildUrl(
5756
export function execute(
5857
path: string,
5958
parameters: qs.ParsedUrlQueryInput,
60-
timeout: number,
59+
timeout: number
6160
): Promise<string> {
6261
const url = buildUrl(path, {
6362
...parameters,
6463
source: getSource(),
6564
});
6665

67-
// Check if we should use a proxy
68-
const urlObj = new URL(url);
69-
const shouldUseProxy = !config.no_proxy?.split(",").some((domain) =>
70-
urlObj.hostname.endsWith(domain.trim())
71-
);
72-
73-
const proxyUrl = shouldUseProxy
74-
? (urlObj.protocol === "https:" ? config.https_proxy : config.http_proxy)
75-
: undefined;
76-
7766
return new Promise((resolve, reject) => {
7867
let timer: number;
7968

@@ -107,18 +96,14 @@ export function execute(
10796
if (timer) clearTimeout(timer);
10897
};
10998

110-
const options: https.RequestOptions = {
111-
timeout: timeout > 0 ? timeout : undefined,
112-
};
113-
114-
if (proxyUrl) {
115-
options.agent = new HttpsProxyAgent(proxyUrl);
116-
}
99+
const options =
100+
(parameters.requestOptions as http.RequestOptions) ||
101+
config.requestOptions ||
102+
{};
117103

118-
const req = https.get(url, options, handleResponse).on(
119-
"error",
120-
handleError,
121-
);
104+
const req = https
105+
.get(url, options, handleResponse)
106+
.on("error", handleError);
122107

123108
if (timeout > 0) {
124109
timer = setTimeout(() => {

0 commit comments

Comments
 (0)