]> Cypherpunks repositories - gostls13.git/commitdiff
net/http: remove redundant port validation
authorDerek Phan <derekphan94@gmail.com>
Tue, 13 Aug 2019 01:05:19 +0000 (01:05 +0000)
committerDaniel Martí <mvdan@mvdan.cc>
Mon, 2 Sep 2019 09:45:08 +0000 (09:45 +0000)
The URL port is already checked in net/url, so we can remove the redundant validation in net/http.

Fixes #33600

Change-Id: I62511a452df6262d4b66180933758d34627ff9df
GitHub-Last-Rev: c19afa31025fee68ba0601bb75e9e20e09a36822
GitHub-Pull-Request: golang/go#33611
Reviewed-on: https://go-review.googlesource.com/c/go/+/190057
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/net/http/transport.go

index ee279877e02e2cede7ed3e2016ce518642f89966..f5e482d3f7b3d14acfb9d5b98689bbb408e698f8 100644 (file)
@@ -710,20 +710,10 @@ func resetProxyConfig() {
 }
 
 func (t *Transport) connectMethodForRequest(treq *transportRequest) (cm connectMethod, err error) {
-       // TODO: the validPort check is redundant after CL 189258, as url.URL.Port
-       // only returns valid ports now. golang.org/issue/33600
-       if port := treq.URL.Port(); !validPort(port) {
-               return cm, fmt.Errorf("invalid URL port %q", port)
-       }
        cm.targetScheme = treq.URL.Scheme
        cm.targetAddr = canonicalAddr(treq.URL)
        if t.Proxy != nil {
                cm.proxyURL, err = t.Proxy(treq.Request)
-               if err == nil && cm.proxyURL != nil {
-                       if port := cm.proxyURL.Port(); !validPort(port) {
-                               return cm, fmt.Errorf("invalid proxy URL port %q", port)
-                       }
-               }
        }
        cm.onlyH1 = treq.requiresHTTP1()
        return cm, err
@@ -2702,15 +2692,3 @@ func (cl *connLRU) remove(pc *persistConn) {
 func (cl *connLRU) len() int {
        return len(cl.m)
 }
-
-// validPort reports whether p (without the colon) is a valid port in
-// a URL, per RFC 3986 Section 3.2.3, which says the port may be
-// empty, or only contain digits.
-func validPort(p string) bool {
-       for _, r := range []byte(p) {
-               if r < '0' || r > '9' {
-                       return false
-               }
-       }
-       return true
-}