global-agent
global-agent copied to clipboard
Do not proxy traffic to sockets
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!