Commit e31bd588 authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

http2: allow Transport to connect to https://[v6literal]/ without port

Fixes golang/go#18248

Change-Id: I271fbcc68a86f20c57b258c2e25788908dafdd94
Reviewed-on: https://go-review.googlesource.com/34143Reviewed-by: 's avatarTom Bergan <tombergan@google.com>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent cbed01e8
...@@ -315,6 +315,10 @@ func authorityAddr(scheme string, authority string) (addr string) { ...@@ -315,6 +315,10 @@ func authorityAddr(scheme string, authority string) (addr string) {
if a, err := idna.ToASCII(host); err == nil { if a, err := idna.ToASCII(host); err == nil {
host = a host = a
} }
// IPv6 address literal, without a port:
if strings.HasPrefix(host, "[") && strings.HasSuffix(host, "]") {
return host + ":" + port
}
return net.JoinHostPort(host, port) return net.JoinHostPort(host, port)
} }
......
...@@ -2892,3 +2892,24 @@ func TestTransportRetryAfterGOAWAY(t *testing.T) { ...@@ -2892,3 +2892,24 @@ func TestTransportRetryAfterGOAWAY(t *testing.T) {
} }
} }
} }
func TestAuthorityAddr(t *testing.T) {
tests := []struct {
scheme, authority string
want string
}{
{"http", "foo.com", "foo.com:80"},
{"https", "foo.com", "foo.com:443"},
{"https", "foo.com:1234", "foo.com:1234"},
{"https", "1.2.3.4:1234", "1.2.3.4:1234"},
{"https", "1.2.3.4", "1.2.3.4:443"},
{"https", "[::1]:1234", "[::1]:1234"},
{"https", "[::1]", "[::1]:443"},
}
for _, tt := range tests {
got := authorityAddr(tt.scheme, tt.authority)
if got != tt.want {
t.Errorf("authorityAddr(%q, %q) = %q; want %q", tt.scheme, tt.authority, got, tt.want)
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment