Skip to content

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

Closed
@Matt3o12

Description

@Matt3o12

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: 127.0.0.1 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. 127.0.0.1 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 example.org:12345) but got: Get http://127.0.0.1: dial tcp 127.0.0.1:80: 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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationIssues describing a change to documentation.FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.help wanted

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions