Skip to content
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

net/http: document that ProxyFromEnvironment also ignores loopback addresses #33695

Matt3o12 opened this issue Aug 17, 2019 · 2 comments


Copy link

@Matt3o12 Matt3o12 commented Aug 17, 2019

What version of Go are you using (go version)?

go version go1.11.12 linux/amd64 (but the code seems to indicate that this also happens on master).

This also seems to be affecting all platforms.

What did you do?

I set the local proxy to some address. The address does not really matter, because the client never connects to it (unexpected). http.Get to the loopback ip: or [::1].

What did you expect to see?

Since the docs 1, 2 specifically mention that only requests who's req.URL.Host is localhost get ignored (not proxied), it is to be expected that the loopback would still work (e.g. or [::1]). Instead, the code ensures that the Host is neither localhost nor any loopback ip.

What did you see instead?

The request never made it to the proxy, it went to the website directly. (I expected to see something along those lines: cannot connect to proxy but got: Get dial tcp connect: connection refused.

The documentation should be updated to point out that any loopback ip address will also get ignored. It would also be helpful to post the workaround mentioned here where it was discussed why localhost is ignored and how to "disable" that (using localhost.localdomain or localhost4, which is available on every linux machine works fine). That would have saved me quit a bit of time since the thread was hard to find.

It would probably be also worth discussing why this was implemented in the first place. If you don't want to use a proxy, there are several ways to do it (set Transport.Proxy = nil or set the environment variable noproxy). This makes debugging client requests harder then it needs to be (I find it easiest to use mitm-proxy to verify that all headers, etc are set correctly).

@bcmills bcmills changed the title Doc: ProxyFromEnvironment also ignores + workaround net/http: document that ProxyFromEnvironment also ignores loopback addresses Aug 19, 2019
@bcmills bcmills added this to the Unplanned milestone Aug 19, 2019
Copy link

@tomocy tomocy commented Aug 21, 2019

I would like to handle it.

Sent with GitHawk

Copy link

@gopherbot gopherbot commented Aug 22, 2019

Change mentions this issue: httpproxy: document all loopbacks are special cased not just localhost

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants