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

x/net/http/httproxy: Never uses proxy for localhost #28866

Open
vfaronov opened this issue Nov 19, 2018 · 9 comments
Open

x/net/http/httproxy: Never uses proxy for localhost #28866

vfaronov opened this issue Nov 19, 2018 · 9 comments

Comments

@vfaronov
Copy link

@vfaronov vfaronov commented Nov 19, 2018

golang.org/x/net/http/httproxy has a hardcoded rule whereby requests to localhost 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 on localhost, 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 like NO_PROXY=foo.invalid. But a 100% backwards-compatible solution would require some hack along the lines of NO_PROXY=but_actually_localhost_ok or HTTP_PROXY_LOCALHOST=yes.

@gopherbot gopherbot added this to the Unreleased milestone Nov 19, 2018
@bcmills
Copy link
Member

@bcmills bcmills commented Nov 19, 2018

(Attn. @bradfitz)

@bradfitz
Copy link
Contributor

@bradfitz bradfitz commented Nov 19, 2018

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.

@vfaronov
Copy link
Author

@vfaronov vfaronov commented Nov 19, 2018

@bradfitz Not sure I’m following you. The function returns true (use proxy) only if none of the NO_PROXY rules match the request. So if you just move the check past all those rules, it will still fire unavoidably for all localhost requests.

@vfaronov
Copy link
Author

@vfaronov vfaronov commented Feb 8, 2019

FWIW, I have found this easy to work around for my use cases (I add tsohlacol to my /etc/hosts and put it in my URLs instead of localhost), so I’d be OK with closing this issue.

@JoelPagliuca
Copy link

@JoelPagliuca JoelPagliuca commented Jan 7, 2020

👋 Hi all, just wasted about half an hour trying to figure out why requests to localhost weren't respecting my http_proxy. Can this be documented somewhere if this is a permanent feature of the http.DefaultClient

@bradfitz
Copy link
Contributor

@bradfitz bradfitz commented Jan 7, 2020

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.

@vbisbest
Copy link

@vbisbest vbisbest commented Jun 16, 2020

@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.

@fraenkel
Copy link
Contributor

@fraenkel fraenkel commented Jun 17, 2020

Just for reference #1589

@gopherbot
Copy link

@gopherbot gopherbot commented Jun 20, 2020

Change https://golang.org/cl/239164 mentions this issue: http/httpproxy: Allow localhost to be proxied

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

Successfully merging a pull request may close this issue.

None yet
7 participants
You can’t perform that action at this time.