fixed httpclient
This commit is contained in:
parent
a282dac6cd
commit
557c157228
10 changed files with 603 additions and 427 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import { HttpsProxyAgent } from 'https-proxy-agent';
|
||||
import { SocksProxyAgent } from 'socks-proxy-agent';
|
||||
import type { ProxyConfig } from './types.js';
|
||||
import { validateProxyConfig } from './types.js';
|
||||
|
||||
export class ProxyManager {
|
||||
/**
|
||||
|
|
@ -28,21 +29,11 @@ export class ProxyManager {
|
|||
throw new Error(`Unsupported proxy type: ${type}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate proxy configuration
|
||||
*/
|
||||
static validateConfig(proxy: ProxyConfig): void {
|
||||
if (!proxy.host) {
|
||||
throw new Error('Proxy host is required');
|
||||
}
|
||||
|
||||
if (!proxy.port || proxy.port < 1 || proxy.port > 65535) {
|
||||
throw new Error('Invalid proxy port');
|
||||
}
|
||||
|
||||
if (!['http', 'https', 'socks4', 'socks5'].includes(proxy.type)) {
|
||||
throw new Error(`Invalid proxy type: ${proxy.type}`);
|
||||
}
|
||||
// Use the centralized validation function
|
||||
validateProxyConfig(proxy);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue