moved shutdown handler to own library
This commit is contained in:
parent
8d0da5cf5c
commit
97dcd30223
12 changed files with 712 additions and 201 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue