diff options
| author | Emmanuel Odeke <emm.odeke@gmail.com> | 2016-04-16 02:04:00 -0700 |
|---|---|---|
| committer | Brad Fitzpatrick <bradfitz@golang.org> | 2016-04-16 15:31:33 +0000 |
| commit | 26ecb42fb4c5ee1d8b64f12e5bb8df6549523d23 (patch) | |
| tree | c68d90902ad39ad019b60c98b6ac9841097b9543 /src/net/http/http.go | |
| parent | 585590549a3c6e26e7963081e11478a1913744a6 (diff) | |
| download | go-26ecb42fb4c5ee1d8b64f12e5bb8df6549523d23.tar.xz | |
net/http: normalize empty port in URL.Host's ":port"
- Ensures that the empty port and preceeding ":"
in a URL.Host are stripped.
Normalize the empty port in a URL.Host's ":port" as
mandated by RFC 3986 Section 6.2.3 which states that:
`Likewise an explicit ":port", for which the port is empty or
the default for the scheme, is equivalent to one where the port
and its ":" delimiter are elided and thus should be
removed by scheme-based normalization.`
- Moves function `hasPort` from client.go (where it was defined but
not used directly), to http.go the common area.
Fixes #14836
Change-Id: I2067410377be9c71106b1717abddc2f8b1da1c03
Reviewed-on: https://go-review.googlesource.com/22140
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/net/http/http.go')
| -rw-r--r-- | src/net/http/http.go | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/net/http/http.go b/src/net/http/http.go index 7484348f52..a121628632 100644 --- a/src/net/http/http.go +++ b/src/net/http/http.go @@ -4,6 +4,10 @@ package http +import ( + "strings" +) + // maxInt64 is the effective "infinite" value for the Server and // Transport's byte-limiting readers. const maxInt64 = 1<<63 - 1 @@ -18,3 +22,16 @@ type contextKey struct { } func (k *contextKey) String() string { return "net/http context value " + k.name } + +// Given a string of the form "host", "host:port", or "[ipv6::address]:port", +// return true if the string includes a port. +func hasPort(s string) bool { return strings.LastIndex(s, ":") > strings.LastIndex(s, "]") } + +// removeEmptyPort strips the empty port in ":port" to "" +// as mandated by RFC 3986 Section 6.2.3. +func removeEmptyPort(host string) string { + if hasPort(host) { + return strings.TrimSuffix(host, ":") + } + return host +} |
