Skip to content

Commit 94e3413

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

File tree

2 files changed

+8
-38
lines changed

2 files changed

+8
-38
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: 6 additions & 22 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";
@@ -64,16 +63,6 @@ export function execute(
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,13 @@ 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 = (parameters.requestOptions as http.RequestOptions) ||
100+
config.requestOptions ||
101+
{};
117102

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

123107
if (timeout > 0) {
124108
timer = setTimeout(() => {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy