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: document outgoing Host header origin in more places #34124

Open
tufanbarisyildirim opened this issue Sep 5, 2019 · 3 comments

Comments

@tufanbarisyildirim
Copy link

commented Sep 5, 2019

What version of Go are you using (go version)?

$ go version
go version go1.12.5 darwin/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOARCH="amd64"
GOOS="darwin"

What did you do?

https://play.golang.org/p/O5Y6dEi_hqx

What did you expect to see?

I expected to see that setting a Host: header actually sends hosts and sets req.Host
map[Accept-Encoding:[gzip] Host:[example.com] User-Agent:[My Test User Agent 1.1]]

What did you see instead?

I see that it just sets Hosts from url and uses req.Host if exists.
map[Accept-Encoding:[gzip] Host:[127.0.0.1:2] User-Agent:[My Test User Agent 1.1]]

I see some closed issues, but I have a few more words about it, It is documented that we need to set .Host to send host header and there are few more headers that calculated in request.write but for example User-Agent is being overwritten but it does not do this for Host.
https://github.com/golang/go/blob/master/src/net/http/request.go#L553 on this comment we see that it says

// Find the target host. Prefer the Host: header, but if that
	// is not given, use the host from the request URL.

but it does not even look at host header.

tufanbarisyildirim added a commit to tufanbarisyildirim/go that referenced this issue Sep 5, 2019
net/http: fix not setting request host from Host header fixes golang#…
…34124

The comment actually says it will prefer the Host header if is that given. But it does not.
@gopherbot

This comment has been minimized.

Copy link

commented Sep 5, 2019

Change https://golang.org/cl/193600 mentions this issue: net/http: fix not setting request host from Host header fixes #34124

@FiloSottile FiloSottile changed the title net/http does not set http.Request.Host when we add Host header. net/http: set http.Request.Host from Host header Sep 10, 2019

@FiloSottile FiloSottile added this to the Unplanned milestone Sep 10, 2019

@FiloSottile

This comment has been minimized.

Copy link
Member

commented Sep 10, 2019

/cc @bradfitz

@bradfitz

This comment has been minimized.

Copy link
Member

commented Sep 11, 2019

We can document the current behavior more, but I'm very reluctant to change the behavior more at this point.

We currently have two fields we consult for the Host header. First Request.Host, else Request.URL.Host.

This is documented on Request.URL:

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

        // For client requests, the URL's Host specifies the server to
        // connect to, while the Request's Host field optionally
        // specifies the Host header value to send in the HTTP
        // request.
        URL *url.URL

We could document that more on Request.Header and Request.Host too.

You're proposing to add a third level in there (Request.Header["Host"]) between the Request.Host and Request.URL.Host. That might be intuitive to some, but it's also just more complexity and compatibility support to maintain going forward. (And might catch other implementations by surprise?)

So we probably shouldn't do anything.

I'd accept a documentation change, though.

@bradfitz bradfitz changed the title net/http: set http.Request.Host from Host header net/http: document outgoing Host header origin in more places Sep 11, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.