bun fetch dont support sock proxy :(

This commit is contained in:
Bojan Kucera 2025-06-06 23:08:54 -04:00
parent 5904af213f
commit 08bb21cee7
5 changed files with 89 additions and 77 deletions

View file

@ -170,6 +170,7 @@ export class HttpClient {
if (this.config.proxy) {
const agent = ProxyManager.createAgent(this.config.proxy);
(requestOptions as any).agent = agent;
console.log('Using proxy agent:', this.config.proxy);
}
// Make the request

View file

@ -2,6 +2,7 @@ import { HttpsProxyAgent } from 'https-proxy-agent';
import { SocksProxyAgent } from 'socks-proxy-agent';
import type { ProxyConfig } from './types.js';
import { validateProxyConfig } from './types.js';
import { HttpProxyAgent } from 'http-proxy-agent';
export class ProxyManager {
/**
@ -11,7 +12,13 @@ export class ProxyManager {
const { protocol, host, port, username, password } = proxy;
let proxyUrl: string;
console.log('Creating proxy agent with config:', {
protocol,
host,
port,
username,
password
});
if (username && password) {
proxyUrl = `${protocol}://${encodeURIComponent(username)}:${encodeURIComponent(password)}@${host}:${port}`;
} else {
@ -20,6 +27,7 @@ export class ProxyManager {
switch (protocol) {
case 'http':
return new HttpProxyAgent(proxyUrl);
case 'https':
return new HttpsProxyAgent(proxyUrl);
case 'socks4':

View file

@ -35,6 +35,7 @@ export interface RequestConfig {
method?: HttpMethod;
url: string;
headers?: Record<string, string>;
proxy?: ProxyConfig;
body?: any;
timeout?: number;
retries?: number;