Skip to content

Commit

Permalink
upgrade http/https/socks proxy agents
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBoroer committed Jan 19, 2025
1 parent 5bb329f commit 315f638
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 57 deletions.
122 changes: 86 additions & 36 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@
"gamedig": "^4.2.0",
"html-escaper": "^3.0.3",
"http-graceful-shutdown": "~3.1.7",
"http-proxy-agent": "~5.0.0",
"https-proxy-agent": "~5.0.1",
"http-proxy-agent": "~7.0.2",
"https-proxy-agent": "~7.0.6",
"iconv-lite": "~0.6.3",
"isomorphic-ws": "^5.0.0",
"jsesc": "~3.0.2",
Expand Down Expand Up @@ -140,7 +140,7 @@
"semver": "~7.5.4",
"socket.io": "~4.8.0",
"socket.io-client": "~4.8.0",
"socks-proxy-agent": "6.1.1",
"socks-proxy-agent": "~8.0.5",
"tar": "~6.2.1",
"tcp-ping": "~0.1.1",
"thirty-two": "~1.0.2",
Expand Down
30 changes: 12 additions & 18 deletions server/proxy.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { R } = require("redbean-node");
const HttpProxyAgent = require("http-proxy-agent");
const HttpsProxyAgent = require("https-proxy-agent");
const SocksProxyAgent = require("socks-proxy-agent");
const { HttpProxyAgent } = require("http-proxy-agent");
const { HttpsProxyAgent } = require("https-proxy-agent");
const { SocksProxyAgent } = require("socks-proxy-agent");
const { debug } = require("../src/util");
const { UptimeKumaServer } = require("./uptime-kuma-server");

Expand Down Expand Up @@ -97,41 +97,35 @@ class Proxy {
let httpAgent;
let httpsAgent;

const proxyOptions = {
protocol: proxy.protocol,
host: proxy.host,
port: proxy.port,
};
const proxyUrl = new URL(`${proxy.protocol}://${proxy.host}:${proxy.port}`);

if (proxy.auth) {
proxyOptions.auth = `${proxy.username}:${proxy.password}`;
proxyUrl.username = proxy.username;
proxyUrl.password = proxy.password;
}

debug(`Proxy Options: ${JSON.stringify(proxyOptions)}`);
debug(`Proxy URL: ${proxyUrl.toString()}`);
debug(`HTTP Agent Options: ${JSON.stringify(httpAgentOptions)}`);
debug(`HTTPS Agent Options: ${JSON.stringify(httpsAgentOptions)}`);

switch (proxy.protocol) {
case "http":
case "https":
httpAgent = new HttpProxyAgent({
...httpAgentOptions || {},
...proxyOptions
httpAgent = new HttpProxyAgent(proxyUrl.toString(), {
...(httpAgentOptions || {}),
});

httpsAgent = new HttpsProxyAgent({
...httpsAgentOptions || {},
...proxyOptions,
httpsAgent = new HttpsProxyAgent(proxyUrl.toString(), {
...(httpsAgentOptions || {}),
});
break;
case "socks":
case "socks5":
case "socks5h":
case "socks4":
agent = new SocksProxyAgent({
agent = new SocksProxyAgent(proxyUrl.toString(), {
...httpAgentOptions,
...httpsAgentOptions,
...proxyOptions,
tls: {
rejectUnauthorized: httpsAgentOptions.rejectUnauthorized,
},
Expand Down

0 comments on commit 315f638

Please sign in to comment.