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/httputil: permit ReverseProxy to change Host header #14413

Closed
linquize opened this issue Feb 19, 2016 · 4 comments
Closed

net/http/httputil: permit ReverseProxy to change Host header #14413

linquize opened this issue Feb 19, 2016 · 4 comments

Comments

@linquize
Copy link

net/http/httputil: ReverseProxy
Currently it preserves HTTP request Host header.
However, this may cause problem for some servers complaining Host not match.
I suggest to have a option to change Host header

For example: A reverse proxy
http://a.com/* -> http://192.168.1.123/*
The client sends HTTP request with header Host: a.com
After forwarding, the server expects HTTP request header Host: 192.168.1.123, so we need to change it.

In https://github.com/golang/go/blob/master/src/net/http/httputil/reverseproxy.go

func NewSingleHostReverseProxy(target *url.URL) *ReverseProxy {
    ......
    req.URL.Host = target.Host
    req.Host = target.Host // Add this line to change Host header
    ......
}
@danp
Copy link
Contributor

danp commented Feb 19, 2016

Do you have an example that shows the target receives a different Host header? As the docs say, Request.URL.Host is the server to connect to, Request.Host is the value used for the Host header.

@danp
Copy link
Contributor

danp commented Feb 19, 2016

I believe this is also specifically tested for in this test. Note the checking of req.Host in the backend server to verify it stays the same as what was in the original request sent to the proxy.

@danp
Copy link
Contributor

danp commented Feb 19, 2016

Sorry, I misread. If you want to modify the Host header in this way you'll probably need to define your own ReverseProxy with a custom Director.

@ianlancetaylor ianlancetaylor changed the title net/http/httputil: ReverseProxy can change Host header net/http/httputil: permit ReverseProxy to change Host header Feb 19, 2016
@ianlancetaylor ianlancetaylor added this to the Unplanned milestone Feb 19, 2016
@bradfitz
Copy link
Contributor

Closing due to lack of reply. I think this is probably already sufficiently configurable.

@golang golang locked and limited conversation to collaborators Feb 28, 2017
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

5 participants