-
Notifications
You must be signed in to change notification settings - Fork 18k
net/http: miss host header when serve as forward proxy. #16265
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
Comments
According to RFC 7230, Section 5.4 states When a proxy receives a request with an absolute-form of request-target, the proxy MUST ignore the received Host header field (if any) and instead replace it with the host information of the request-target. |
That is RFC definition for what a proxy must do, but server still need the Host imformation. |
https://tools.ietf.org/html/rfc7230#section-5.4 also says:
Go is forcing the two values to be the same. In fact, there's even an old comment in the code about this in // RFC 2616: Must treat
// GET /index.html HTTP/1.1
// Host: www.google.com
// and
// GET http://www.google.com/index.html HTTP/1.1
// Host: doesntmatter
// the same. In the second case, any Host line is ignored.
req.Host = req.URL.Host
if req.Host == "" {
req.Host = req.Header.get("Host")
} So I think this is working as intended. Feel free to clarify if I misunderstood something. |
There is nothing conflict with RFC. But that has no way for me to do Also, as an HTTP handler, it has no way to get the raw http header |
Correct, Go does not permit you to get at a bogus Host header. It's bogus if it differs from an absolute request-target, as far as I understand from the spec. If you need to test a proxy and curl doesn't let you generate the request you want to, you could probably generate it with a different program. |
go version go1.6.2 darwin/amd64
darwin/amd64
run this program on local.
on another terminal, run:
I ran
sudo tcpdump -i any -A port 12306
and it printsthe program prints
Is it right that host header should be
haha
The text was updated successfully, but these errors were encountered: