Skip to content

Commit af47b85

Browse files
socks5 update
1 parent 1c61116 commit af47b85

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/utils/makeProxyAgent.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { socksDispatcher } from 'fetch-socks';
22
import { HttpsProxyAgent } from 'https-proxy-agent';
33
import { SocksProxyAgent } from 'socks-proxy-agent';
4-
import { ProxyAgent } from 'undici';
4+
import { Agent, ProxyAgent } from 'undici';
55

66
type Proxy = {
77
host: string;
@@ -26,7 +26,16 @@ function selectProxyAgent(proxyUrl: string): HttpsProxyAgent<string> | SocksProx
2626
return new HttpsProxyAgent(url);
2727
case PROXY_SOCKS_PROTOCOL:
2828
case PROXY_SOCKS5_PROTOCOL:
29-
return new SocksProxyAgent(url);
29+
30+
let urlSocks = '';
31+
32+
if(url.username && url.password) {
33+
urlSocks = `socks://${url.username}:${url.password}@${url.hostname}:${url.port}`;
34+
} else {
35+
urlSocks = `socks://${url.hostname}:${url.port}`;
36+
}
37+
38+
return new SocksProxyAgent(urlSocks);
3039
default:
3140
throw new Error(`Unsupported proxy protocol: ${url.protocol}`);
3241
}

0 commit comments

Comments
 (0)