Skip to content

Commit

Permalink
add keepAlive for proxy agent
Browse files Browse the repository at this point in the history
  • Loading branch information
Last-Order committed Jan 10, 2024
1 parent b0c0cdf commit 7249b25
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 63 deletions.
114 changes: 57 additions & 57 deletions npm-shrinkwrap.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 @@ -30,14 +30,14 @@
"license": "GPL-3.0-or-later",
"dependencies": {
"@eridanussora/reconnecting-websocket": "^4.4.2",
"agent-base": "^6.0.2",
"agent-base": "^7.1.0",
"axios": "^1.6.0",
"chalk": "^2.4.2",
"cli-progress": "^3.10.0",
"crypto-js": "^3.3.0",
"erii": "^2.0.6",
"https-proxy-agent": "^5.0.0",
"socks-proxy-agent": "^6.1.0",
"https-proxy-agent": "^7.0.2",
"socks-proxy-agent": "^8.0.2",
"ws": "^7.4.6"
},
"devDependencies": {
Expand Down
12 changes: 9 additions & 3 deletions src/utils/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ class ProxyAgentHelper {
}
if (proxy.startsWith("http://") || proxy.startsWith("https://")) {
// HTTP Proxy
this.proxyAgentInstance = new HttpsProxyAgent(proxy);
this.proxyAgentInstance = new HttpsProxyAgent(proxy, {
keepAlive: true,
});
logger.debug(`HTTP/HTTPS Proxy set: ${proxy}`);
} else if (proxy.startsWith("socks")) {
if (proxy.startsWith("socks4")) {
Expand All @@ -31,7 +33,9 @@ class ProxyAgentHelper {
// Socks5 Proxy
try {
const [_, host, port] = proxy.match(/socks5?(?:(?<=5)h)?[::]\/\/(.+)[::](\d+)/);
this.proxyAgentInstance = new SocksProxyAgent(`socks5h://${host}:${port}`);
this.proxyAgentInstance = new SocksProxyAgent(`socks5h://${host}:${port}`, {
keepAlive: true,
});
logger.debug(`Socks5 Proxy set: socks5h://${host}:${port}`);
} catch (e) {
throw new InvalidProxyServerError("Proxy server invalid.");
Expand All @@ -40,7 +44,9 @@ class ProxyAgentHelper {
// For compatibility, use proxy without protocol as socks5 proxy
try {
const [_, host, port] = proxy.match(/(.+)[::](\d+)/);
this.proxyAgentInstance = new SocksProxyAgent(`socks5h://${host}:${port}`);
this.proxyAgentInstance = new SocksProxyAgent(`socks5h://${host}:${port}`, {
keepAlive: true,
});
logger.debug(`Socks5 Proxy set: socks5h://${host}:${port}`);
} catch (e) {
throw new InvalidProxyServerError("Proxy server invalid.");
Expand Down

0 comments on commit 7249b25

Please sign in to comment.