undici icon indicating copy to clipboard operation
undici copied to clipboard

Feature: Rewrite ProxyAgent

Open PandaWorker opened this issue 7 months ago • 4 comments

This would solve...

I want connectors in undici to be responsible for all connections to the destination server. This allows you to configure agents more flexibly.

The implementation should look like...

I wrote a separate package to show how it is necessary and will be more correct to use a proxy

buildHttpProxyConnector buildSocksProxyConnector

import {
  buildHttpProxyConnector,
  buildSocksProxyConnector,
  buildSocksProxyChainConnector
} from '@undicijs/proxy';
import { request, Agent } from 'undici';

// Connectors only for wrapping socket connection for distonation host
const httpProxyConnector = buildHttpProxyConnector('http://3proxy:8080');
const socksProxyConnector = buildSocksProxyConnector('socks5://3proxy:1080');
const socksProxyChainConnector = buildSocksProxyChainConnector(['socks5://3proxy:1080', 'socks5://3proxy:1081']);

// Agents managing of openned sockets and dispatching requests
const httpProxyAgent = new Agent({connect: httpProxyConnector});
const socksProxyAgent = new Agent({connect: socksProxyConnector});
const socksProxyChainAgent = new Agent({connect: socksProxyChainConnector});

Additional context

You can look at it in full at https://jsr.io/@undicijs/[email protected]

I think this would be a better solution. What do you say about this?

PandaWorker avatar Jul 09 '24 20:07 PandaWorker