From 26ecb42fb4c5ee1d8b64f12e5bb8df6549523d23 Mon Sep 17 00:00:00 2001 From: Emmanuel Odeke Date: Sat, 16 Apr 2016 02:04:00 -0700 Subject: 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 Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/net/http/request.go | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/net/http/request.go') diff --git a/src/net/http/request.go b/src/net/http/request.go index bac2de1a2e..a49ab36964 100644 --- a/src/net/http/request.go +++ b/src/net/http/request.go @@ -660,6 +660,8 @@ func NewRequest(method, urlStr string, body io.Reader) (*Request, error) { if !ok && body != nil { rc = ioutil.NopCloser(body) } + // The host's colon:port should be normalized. See Issue 14836. + u.Host = removeEmptyPort(u.Host) req := &Request{ Method: method, URL: u, -- cgit v1.3-6-g1900