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: Request.ReadRequest() should not delete Request.Header["Host"] #13134

Closed
yamada95 opened this issue Nov 3, 2015 · 1 comment
Closed

Comments

@yamada95
Copy link

@yamada95 yamada95 commented Nov 3, 2015

I think Request.Header["Host"] should not be deleted when parsing the request.

For example, if I use the net/http to write a proxy server, listening on 127.0.0.1:8080, and issue the following command:
curl --proxy "127.0.0.1:8080" -H "Host: domain.com" "http://130.130.10.10/ping"

The proxy should deliver the Host header to origin server 130.130.10.10, but it's already deleted by Request.ReadRequest() when reading request from client(https://golang.org/src/net/http/request.go?h=http#L714). In this case, if the origin server is configured as a nginx virtual server server_name domain.com, it will return 404 because of mismatching host name.

@bradfitz

This comment has been minimized.

Copy link
Contributor

@bradfitz bradfitz commented Nov 3, 2015

The Host header is put into the Request.Host field:

https://golang.org/pkg/net/http/#Request

It's been like that for ages. Changing it now, regardless of whether it's a good idea, would be a incompatible change.

In any case, you seem to have a concrete problem about writing a proxy. Let's discuss that instead on one of the forums: https://golang.org/wiki/Questions

@bradfitz bradfitz closed this Nov 3, 2015
@golang golang locked and limited conversation to collaborators Nov 4, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

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