Removendo uso do undici com proxy socks

This commit is contained in:
Jeferson Ramos 2025-11-19 13:34:33 -03:00
parent 3818313161
commit 3b139078c3

View File

@ -19,11 +19,13 @@ function selectProxyAgent(proxyUrl: string): HttpsProxyAgent<string> | SocksProx
// the end so, we add the protocol constants without the `:` to avoid confusion. // the end so, we add the protocol constants without the `:` to avoid confusion.
const PROXY_HTTP_PROTOCOL = 'http:'; const PROXY_HTTP_PROTOCOL = 'http:';
const PROXY_SOCKS_PROTOCOL = 'socks:'; const PROXY_SOCKS_PROTOCOL = 'socks:';
const PROXY_SOCKS5_PROTOCOL = 'socks5:';
switch (url.protocol) { switch (url.protocol) {
case PROXY_HTTP_PROTOCOL: case PROXY_HTTP_PROTOCOL:
return new HttpsProxyAgent(url); return new HttpsProxyAgent(url);
case PROXY_SOCKS_PROTOCOL: case PROXY_SOCKS_PROTOCOL:
case PROXY_SOCKS5_PROTOCOL:
return new SocksProxyAgent(url); return new SocksProxyAgent(url);
default: default:
throw new Error(`Unsupported proxy protocol: ${url.protocol}`); throw new Error(`Unsupported proxy protocol: ${url.protocol}`);
@ -45,7 +47,7 @@ export function makeProxyAgent(proxy: Proxy | string): HttpsProxyAgent<string> |
return selectProxyAgent(proxyUrl); return selectProxyAgent(proxyUrl);
} }
export function makeProxyAgentUndici(proxy: Proxy | string): ProxyAgent { export function makeProxyAgentUndici(proxy: Proxy | string): ProxyAgent|SocksProxyAgent {
let proxyUrl: string let proxyUrl: string
let protocol: string let protocol: string
@ -73,10 +75,10 @@ export function makeProxyAgentUndici(proxy: Proxy | string): ProxyAgent {
switch (protocol) { switch (protocol) {
case PROXY_HTTP_PROTOCOL: case PROXY_HTTP_PROTOCOL:
case PROXY_HTTPS_PROTOCOL: case PROXY_HTTPS_PROTOCOL:
return new ProxyAgent(proxyUrl)
case PROXY_SOCKS4_PROTOCOL: case PROXY_SOCKS4_PROTOCOL:
case PROXY_SOCKS5_PROTOCOL: case PROXY_SOCKS5_PROTOCOL:
return new ProxyAgent(proxyUrl) return new SocksProxyAgent(proxyUrl)
default: default:
throw new Error(`Unsupported proxy protocol: ${protocol}`) throw new Error(`Unsupported proxy protocol: ${protocol}`)
} }