moved shutdown handler to own library

This commit is contained in:
Bojan Kucera 2025-06-07 10:32:22 -04:00
parent 8d0da5cf5c
commit 97dcd30223
12 changed files with 712 additions and 201 deletions

View file

@ -1,4 +1,5 @@
import { ProxyAgent } from 'undici';
import { SocksProxyAgent } from 'socks-proxy-agent';
import type { ProxyConfig } from './types.js';
export class ProxyManager {
@ -22,7 +23,23 @@ export class ProxyManager {
}
/**
* Create Undici proxy agent for SOCKS proxies
* Create agent for SOCKS proxies (used with undici)
*/
static createSocksAgent(proxy: ProxyConfig): SocksProxyAgent {
const { protocol, host, port, username, password } = proxy;
let proxyUrl: string;
if (username && password) {
proxyUrl = `${protocol}://${encodeURIComponent(username)}:${encodeURIComponent(password)}@${host}:${port}`;
} else {
proxyUrl = `${protocol}://${host}:${port}`;
}
return new SocksProxyAgent(proxyUrl);
}
/**
* Create Undici proxy agent for HTTP/HTTPS proxies (fallback)
*/
static createUndiciAgent(proxy: ProxyConfig): ProxyAgent {
const { protocol, host, port, username, password } = proxy;