]> Cypherpunks repositories - gostls13.git/commitdiff
[release-branch.go1] net/http: reuse http proxy connections for different http requests
authorAlexey Borzenkov <snaury@gmail.com>
Wed, 13 Jun 2012 20:24:23 +0000 (16:24 -0400)
committerBrad Fitzpatrick <bradfitz@golang.org>
Wed, 13 Jun 2012 20:24:23 +0000 (16:24 -0400)
««« backport d0bc02d414c7
net/http: reuse http proxy connections for different http requests

Comment on cache keys above connectMethod says "http to proxy, http
anywhere after that", however in reality target address was always
included, which prevented http requests to different target
addresses to reuse the same http proxy connection.

R=golang-dev, r, rsc, bradfitz
CC=golang-dev
https://golang.org/cl/5901064

»»»

src/pkg/net/http/proxy_test.go
src/pkg/net/http/transport.go

index 9b320b3aa5b9904f26cc5aba7983f60ba5ddd2b7..5ecffaface93de6a145a1f92d1101579ebcaf39b 100644 (file)
@@ -5,6 +5,7 @@
 package http
 
 import (
+       "net/url"
        "os"
        "testing"
 )
@@ -46,3 +47,32 @@ func TestUseProxy(t *testing.T) {
                }
        }
 }
+
+var cacheKeysTests = []struct {
+       proxy  string
+       scheme string
+       addr   string
+       key    string
+}{
+       {"", "http", "foo.com", "|http|foo.com"},
+       {"", "https", "foo.com", "|https|foo.com"},
+       {"http://foo.com", "http", "foo.com", "http://foo.com|http|"},
+       {"http://foo.com", "https", "foo.com", "http://foo.com|https|foo.com"},
+}
+
+func TestCacheKeys(t *testing.T) {
+       for _, tt := range cacheKeysTests {
+               var proxy *url.URL
+               if tt.proxy != "" {
+                       u, err := url.Parse(tt.proxy)
+                       if err != nil {
+                               t.Fatal(err)
+                       }
+                       proxy = u
+               }
+               cm := connectMethod{proxy, tt.scheme, tt.addr}
+               if cm.String() != tt.key {
+                       t.Fatalf("{%q, %q, %q} cache key %q; want %q", tt.proxy, tt.scheme, tt.addr, cm.String(), tt.key)
+               }
+       }
+}
index 024975946e52b2073800191a5bc41f917ce5743c..6efe191eb0b0dbf18161f258d4e00a0601f7a9af 100644 (file)
@@ -450,10 +450,14 @@ type connectMethod struct {
 
 func (ck *connectMethod) String() string {
        proxyStr := ""
+       targetAddr := ck.targetAddr
        if ck.proxyURL != nil {
                proxyStr = ck.proxyURL.String()
+               if ck.targetScheme == "http" {
+                       targetAddr = ""
+               }
        }
-       return strings.Join([]string{proxyStr, ck.targetScheme, ck.targetAddr}, "|")
+       return strings.Join([]string{proxyStr, ck.targetScheme, targetAddr}, "|")
 }
 
 // addr returns the first hop "host:port" to which we need to TCP connect.