From: Brad Fitzpatrick Date: Tue, 4 Dec 2012 15:09:01 +0000 (-0800) Subject: net/http: clarify that Request.Host may contain a port number X-Git-Tag: go1.1rc2~1724 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=add1bed735e190abb03943a73e415576de211245;p=gostls13.git net/http: clarify that Request.Host may contain a port number Fixes #4172 R=golang-dev, dsymonds CC=golang-dev https://golang.org/cl/6872055 --- diff --git a/src/pkg/net/http/request.go b/src/pkg/net/http/request.go index b9d6289793..0b6e6cbab5 100644 --- a/src/pkg/net/http/request.go +++ b/src/pkg/net/http/request.go @@ -124,6 +124,7 @@ type Request struct { // The host on which the URL is sought. // Per RFC 2616, this is either the value of the Host: header // or the host name given in the URL itself. + // It may be of the form "host:port". Host string // Form contains the parsed form data, including both the URL diff --git a/src/pkg/net/http/request_test.go b/src/pkg/net/http/request_test.go index c0b738c6e6..2f34d12412 100644 --- a/src/pkg/net/http/request_test.go +++ b/src/pkg/net/http/request_test.go @@ -228,6 +228,16 @@ func TestReadRequestErrors(t *testing.T) { } } +func TestNewRequestHost(t *testing.T) { + req, err := NewRequest("GET", "http://localhost:1234/", nil) + if err != nil { + t.Fatal(err) + } + if req.Host != "localhost:1234" { + t.Errorf("Host = %q; want localhost:1234", req.Host) + } +} + func testMissingFile(t *testing.T, req *Request) { f, fh, err := req.FormFile("missing") if f != nil { diff --git a/src/pkg/net/url/url.go b/src/pkg/net/url/url.go index d1fff89da7..692a7fdc04 100644 --- a/src/pkg/net/url/url.go +++ b/src/pkg/net/url/url.go @@ -224,7 +224,7 @@ type URL struct { Scheme string Opaque string // encoded opaque data User *Userinfo // username and password information - Host string + Host string // host or host:port Path string RawQuery string // encoded query values, without '?' Fragment string // fragment for references, without '#'