New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
x/net/http/httproxy: Never uses proxy for localhost #28866
Comments
(Attn. @bradfitz) |
I'm fine moving that special case rule down further pass the explicit match/no-match checks, but let's not add a new environment variable. |
@bradfitz Not sure I’m following you. The function returns |
FWIW, I have found this easy to work around for my use cases (I add |
👋 Hi all, just wasted about half an hour trying to figure out why requests to |
Honestly I don't remember why the localhost exception exists. If somebody could dig through the history to figure that out, that'd be great. Hopefully we could just remove it. But we need to understand why first. |
@bradfitz we need this so we can proxy to localhost locations. I am running web server instances in docker on my local machine for testing. I am trying to sniff the traffic using a go proxy, but it just does not work because of this localhost exception issue. |
Just for reference #1589 |
Change https://golang.org/cl/239164 mentions this issue: |
What do other http clients do in this case? It might be beneficial to at least check curl and some of the popular browsers. Please keep in mind that a major use case for proxies are corporate settings where the settings are often not changeable by end users and the proxy exceptions contain usually some internal services already. In those settings Go tests and Go applications spawning a browser might suddenly stop working. One important application in that area is redirecting an OAuth flow to the browser from the cli or the go trace viewer. |
MY examination of a few applications and runtimes show that the user must be explicit, i.e., if you don't want localhost proxied add it to the NO_PROXY list. |
Related #33695 |
Bitten by this myself today while trying to insert a proxy between my program and a locally running service it was connecting to. Editing Ignoring |
golang.org/x/net/http/httproxy
has a hardcoded rule whereby requests tolocalhost
never use a proxy.This may be a sensible default, but there should be a way to override it. There is no intrinsic reason why a proxy cannot or should not be used for
localhost
. My use case is that I have mocks of remote HTTP services running onlocalhost
, and I want to use mitmproxy to debug the Go program’s traffic to/from these services.One solution might be to use the current default unless there’s a non-empty
NO_PROXY
/NoProxy
environment variable: then I could use some dummy value likeNO_PROXY=foo.invalid
. But a 100% backwards-compatible solution would require some hack along the lines ofNO_PROXY=but_actually_localhost_ok
orHTTP_PROXY_LOCALHOST=yes
.The text was updated successfully, but these errors were encountered: