global-agent icon indicating copy to clipboard operation
global-agent copied to clipboard

Do not proxy traffic to sockets

Open tommyknows opened this issue 2 years ago • 0 comments

First off, thanks a lot for this library!

I am currently facing an issue where I have an application that has two different types of connections:

  • "normal" HTTP connections to some upstream servers
  • TCP HTTP traffic to local sockets, e.g. /var/run/...

The first type of traffic works as expected, however for Socket traffic things get weird. global-agent redirects / routes that traffic through the proxy, and because HTTP requests to sockets do not have a host or port set, something will set localhost:80 as the destination. Now the proxy obviously does not know what to do with it, because the socket-info is lost.

I'm opening this issue because I wanted to ask if it would be possible to add an exception for socket traffic. For example, the easiest solution would be to simply add the following code here:

    if (configuration.socketPath) {
        log.trace({
            destination: request.socketPath,
        }, 'not proxying request; destination is a socket');

        this.fallbackAgent.addRequest(request, configuration);
        return ;
    }

This could also be made configurable through an option, I guess, though because traffic sent to the proxy is "useless" (no / wrong destination attached), I don't see why an option for this could be useful (YMMV 😉)

I'd be happy to open a PR for this, but wanted to get an opinion first.

Thanks!

tommyknows avatar Oct 12 '22 12:10 tommyknows