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: ReverseProxy should (optionally?) set Host header to target #5692

Closed
kisielk opened this issue Jun 12, 2013 · 4 comments
Closed

Comments

@kisielk
Copy link
Contributor

kisielk commented Jun 12, 2013

Currently the ReverseProxy type preserves the Host header from the original request,
which can cause problems with Vhosts and in my experience particularly when proxying to
an HTTPS server using SNI.

Apache's mod_proxy provides an option to preserve the Host header and it defaults to Off
(the opposite of ReverseProxy's behaviour):
http://httpd.apache.org/docs/2.2/mod/mod_proxy.html#proxypreservehost

In section 14.23 of RFC2616 it says: "An HTTP/1.1 proxy MUST ensure that any
request message it forwards does contain an appropriate Host header field that
identifies the service being requested by the proxy" which I understand as setting
the Host header to the target host and not what was originally requested.

I think ReverseProxy should rewrite the Host field appropriately, if not by default then
perhaps enabled by a boolean field.
@gopherbot
Copy link

Comment 1 by cgmurray:

You can set the host in the "director" function in httputil.ReverseProxy, e.g.
func (p *proxy) director(req *http.Request) {
    // ...
    req.Host = "..."
}

@robpike
Copy link
Contributor

robpike commented Jun 12, 2013

Comment 2:

Easy enough to work around. Not worth a package change.

Labels changed: removed priority-triage.

Status changed to WorkingAsIntended.

@kisielk
Copy link
Contributor Author

kisielk commented Jun 13, 2013

Comment 3:

You're right, I wasn't specific enough, this only affects NewSingleHostReverseProxy in
particular. Supposedly the code sets req.URL.Host = target.Host on line 65 but that's
not what I am seeing come through in the actual request.

@kisielk
Copy link
Contributor Author

kisielk commented Jun 13, 2013

Comment 4:

It's probably because req has both req.Host and req.URL.Host fields, with req.Host
taking precedence. The director created by NewSingleHostReverseProxy only updates
req.URL.Host but leaves req.Host at the old value.

rogerso added a commit to rogerso/micro that referenced this issue May 9, 2016
@golang golang locked and limited conversation to collaborators May 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants