Source file src/net/http/proxy_test.go

     1  // Copyright 2009 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package http
     6  
     7  import (
     8  	"net/url"
     9  	"os"
    10  	"testing"
    11  )
    12  
    13  // TODO(mattn):
    14  //	test ProxyAuth
    15  
    16  var cacheKeysTests = []struct {
    17  	proxy  string
    18  	scheme string
    19  	addr   string
    20  	key    string
    21  }{
    22  	{"", "http", "foo.com", "|http|foo.com"},
    23  	{"", "https", "foo.com", "|https|foo.com"},
    24  	{"http://foo.com", "http", "foo.com", "http://foo.com|http|"},
    25  	{"http://foo.com", "https", "foo.com", "http://foo.com|https|foo.com"},
    26  }
    27  
    28  func TestCacheKeys(t *testing.T) {
    29  	for _, tt := range cacheKeysTests {
    30  		var proxy *url.URL
    31  		if tt.proxy != "" {
    32  			u, err := url.Parse(tt.proxy)
    33  			if err != nil {
    34  				t.Fatal(err)
    35  			}
    36  			proxy = u
    37  		}
    38  		cm := connectMethod{proxyURL: proxy, targetScheme: tt.scheme, targetAddr: tt.addr}
    39  		if got := cm.key().String(); got != tt.key {
    40  			t.Fatalf("{%q, %q, %q} cache key = %q; want %q", tt.proxy, tt.scheme, tt.addr, got, tt.key)
    41  		}
    42  	}
    43  }
    44  
    45  func ResetProxyEnv() {
    46  	for _, v := range []string{"HTTP_PROXY", "http_proxy", "NO_PROXY", "no_proxy", "REQUEST_METHOD"} {
    47  		os.Unsetenv(v)
    48  	}
    49  	ResetCachedEnvironment()
    50  }
    51  

View as plain text