]> Cypherpunks repositories - gostls13.git/commitdiff
net/http: clarify that Request.Host may contain a port number
authorBrad Fitzpatrick <bradfitz@golang.org>
Tue, 4 Dec 2012 15:09:01 +0000 (07:09 -0800)
committerBrad Fitzpatrick <bradfitz@golang.org>
Tue, 4 Dec 2012 15:09:01 +0000 (07:09 -0800)
Fixes #4172

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/6872055

src/pkg/net/http/request.go
src/pkg/net/http/request_test.go
src/pkg/net/url/url.go

index b9d62897934cef76a22c7246b8ec2633cc7c3612..0b6e6cbab58697eaab8441bb27a5d29735ae919f 100644 (file)
@@ -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
index c0b738c6e6569828f666496b0cff5e2db4baec3b..2f34d124128d47de91cd9f73d2f9fc8782e92c7b 100644 (file)
@@ -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 {
index d1fff89da79609548fc5cef9bac233e2251a1b18..692a7fdc0484702f579f5c1f123705d751633e97 100644 (file)
@@ -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 '#'