working on proxy service. getting closer
This commit is contained in:
parent
6380165a94
commit
afc1843fdb
5 changed files with 91 additions and 892 deletions
|
|
@ -16,9 +16,6 @@ export class ProxyManager {
|
|||
*/
|
||||
static createProxyUrl(proxy: ProxyInfo): string {
|
||||
const { protocol, host, port, username, password } = proxy;
|
||||
if(protocol.includes('socks')) {
|
||||
return `${protocol}://${host}:${port}`;
|
||||
}
|
||||
if (username && password) {
|
||||
return `${protocol}://${encodeURIComponent(username)}:${encodeURIComponent(password)}@${host}:${port}`;
|
||||
}
|
||||
|
|
@ -32,11 +29,10 @@ export class ProxyManager {
|
|||
this.validateConfig(proxy);
|
||||
|
||||
const proxyUrl = this.createProxyUrl(proxy);
|
||||
console.log(`Using proxy url: ${proxyUrl}`);
|
||||
switch (proxy.protocol) {
|
||||
case 'socks4':
|
||||
case 'socks5':
|
||||
console.log(`Using SOCKS proxy: ${proxyUrl}`);
|
||||
// console.log(`Using SOCKS proxy: ${proxyUrl}`);
|
||||
return new SocksProxyAgent(proxyUrl);
|
||||
case 'http':
|
||||
return new HttpProxyAgent(proxyUrl);
|
||||
|
|
@ -54,12 +50,6 @@ export class ProxyManager {
|
|||
return {
|
||||
httpAgent: agent,
|
||||
httpsAgent: agent,
|
||||
// timeout: 30000,
|
||||
// validateStatus: () => true, // Don't throw errors on HTTP status codes
|
||||
// maxRedirects: 5,
|
||||
// headers: {
|
||||
// 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'
|
||||
// }
|
||||
};
|
||||
}
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue