]> Cypherpunks.ru repositories - gostls13.git/commitdiff
net/http: use canonicalAddr on shouldCopyHeaderOnRedirect
authorGuilherme Rezende <guilhermebr@gmail.com>
Mon, 4 Sep 2017 12:28:27 +0000 (09:28 -0300)
committerTom Bergan <tombergan@google.com>
Mon, 2 Oct 2017 17:21:04 +0000 (17:21 +0000)
Change-Id: Ic3f7f575d3640706adb7d64545ed8027add6c58f
Reviewed-on: https://go-review.googlesource.com/61350
Run-TryBot: Tom Bergan <tombergan@google.com>
Reviewed-by: Tom Bergan <tombergan@google.com>
src/net/http/client.go
src/net/http/client_test.go

index 4c9084ae512df9c89a487639072ac3489fb95d5f..25cd5739fef72e36c0307d50731b7c096ea41954 100644 (file)
@@ -843,16 +843,8 @@ func shouldCopyHeaderOnRedirect(headerKey string, initial, dest *url.URL) bool {
                // directly, we don't know their scope, so we assume
                // it's for *.domain.com.
 
-               // TODO(bradfitz): once issue 16142 is fixed, make
-               // this code use those URL accessors, and consider
-               // "http://foo.com" and "http://foo.com:80" as
-               // equivalent?
-
-               // TODO(bradfitz): better hostname canonicalization,
-               // at least once we figure out IDNA/Punycode (issue
-               // 13835).
-               ihost := strings.ToLower(initial.Host)
-               dhost := strings.ToLower(dest.Host)
+               ihost := canonicalAddr(initial)
+               dhost := canonicalAddr(dest)
                return isDomainOrSubdomain(dhost, ihost)
        }
        // All other headers are copied:
index b9a1c31e43ae8ee9b046acf6b0f69c0ddec9518a..7db74dd4cb287c1768c86ecade8bc773ee1ed8f6 100644 (file)
@@ -1599,8 +1599,12 @@ func TestShouldCopyHeaderOnRedirect(t *testing.T) {
                {"www-authenticate", "http://foo.com/", "http://foo.com/", true},
                {"www-authenticate", "http://foo.com/", "http://sub.foo.com/", true},
                {"www-authenticate", "http://foo.com/", "http://notfoo.com/", false},
-               // TODO(bradfitz): make this test work, once issue 16142 is fixed:
-               // {"www-authenticate", "http://foo.com:80/", "http://foo.com/", true},
+               {"www-authenticate", "http://foo.com/", "https://foo.com/", false},
+               {"www-authenticate", "http://foo.com:80/", "http://foo.com/", true},
+               {"www-authenticate", "http://foo.com:80/", "http://sub.foo.com/", true},
+               {"www-authenticate", "http://foo.com:443/", "https://foo.com/", true},
+               {"www-authenticate", "http://foo.com:443/", "https://sub.foo.com/", true},
+               {"www-authenticate", "http://foo.com:1234/", "http://foo.com/", false},
        }
        for i, tt := range tests {
                u0, err := url.Parse(tt.initialURL)