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 special-cases localhost #7256

Closed
gopherbot opened this issue Feb 4, 2014 · 9 comments
Closed

Comments

@gopherbot
Copy link

by mislav.marohnic:

Go respects HTTP_PROXY environment variables, **except** when the original request is to
"localhost" or "127.0.0.1".

This special case is surprising (it's not documented) and undesired. I've come across
this when I tried to debug a go program that makes HTTP requests by passing all
communication through a HTTP debugging proxy:

  http_proxy=localhost:8888 myprog ...

However since this program makes HTTP requests to a *local test server*, my proxy
configuration was silently ignored.

The only way around this was to literally reimplement `http.ProxyFromEnvironment` in my
program without the needless special case for localhost.

go version 1.2
@bradfitz
Copy link
Contributor

bradfitz commented Feb 4, 2014

Comment 1:

I don't remember why we do that. (in func useProxy)
If we have to keep it, it at least needs to be documented.
Could you dig through the source history and figure out when it was added and why? Also,
do other tools do something like this?

Labels changed: added release-go1.3, repo-main.

Status changed to Accepted.

@adg
Copy link
Contributor

adg commented Feb 4, 2014

Comment 2:

Maybe we have it because "localhost" will likely mean something different for a proxy?

@gopherbot
Copy link
Author

Comment 3 by mislav.marohnic:

Maybe we have it because "localhost" will likely mean something different
That's a good point. However a HTTP proxy doesn't have to be on a remote
machine, like the use case here with a debugging proxy.
If a person wants to explicitly disable hitting the proxy for "localhost"
or 127.0.0.1, then can choose to do so by adding them to NO_PROXY.
https://code.google.com/p/go/source/browse/src/pkg/net/http/transport.go?name=go1.2#553

@bradfitz
Copy link
Contributor

bradfitz commented Feb 4, 2014

Comment 4:

Please see how far back our localhost exception goes. Perhaps it was a hack before we
had NO_PROXY support?

@gopherbot
Copy link
Author

Comment 5 by mislav.marohnic:

@bradfitz: https://golang.org/issue/1589
There existed NO_PROXY support at the time of adding this.

@rsc
Copy link
Contributor

rsc commented Apr 3, 2014

Comment 7:

You can always use an alias for localhost, such as by putting a new entry in /etc/hosts
or often using localhost.localdomain.

@bradfitz
Copy link
Contributor

Comment 8:

Labels changed: added documentation.

@gopherbot
Copy link
Author

Comment 9:

CL https://golang.org/cl/97590043 mentions this issue.

@bradfitz
Copy link
Contributor

Comment 10:

This issue was closed by revision f0bdee1.

Status changed to Fixed.

@rsc rsc added this to the Go1.3 milestone Apr 14, 2015
@rsc rsc removed the release-go1.3 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants