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.
16
var UseProxyTests = []struct {
20
// Never proxy localhost:
21
{"localhost:80", false},
25
{"[::2]", true}, // not a loopback address
27
{"barbaz.net", false}, // match as .barbaz.net
28
{"foobar.com", false}, // have a port but match
29
{"foofoobar.com", true}, // not match as a part of foobar.com
30
{"baz.com", true}, // not match as a part of barbaz.com
31
{"localhost.net", true}, // not match as suffix of address
32
{"local.localhost", true}, // not match as prefix as address
33
{"barbarbaz.net", true}, // not match because NO_PROXY have a '.'
34
{"www.foobar.com", false}, // match because NO_PROXY includes "foobar.com"
37
func TestUseProxy(t *testing.T) {
39
os.Setenv("NO_PROXY", "foobar.com, .barbaz.net")
40
for _, test := range UseProxyTests {
41
if useProxy(test.host+":80") != test.match {
42
t.Errorf("useProxy(%v) = %v, want %v", test.host, !test.match, test.match)
47
var cacheKeysTests = []struct {
53
{"", "http", "foo.com", "|http|foo.com"},
54
{"", "https", "foo.com", "|https|foo.com"},
55
{"http://foo.com", "http", "foo.com", "http://foo.com|http|"},
56
{"http://foo.com", "https", "foo.com", "http://foo.com|https|foo.com"},
59
func TestCacheKeys(t *testing.T) {
60
for _, tt := range cacheKeysTests {
63
u, err := url.Parse(tt.proxy)
69
cm := connectMethod{proxy, tt.scheme, tt.addr}
70
if got := cm.key().String(); got != tt.key {
71
t.Fatalf("{%q, %q, %q} cache key = %q; want %q", tt.proxy, tt.scheme, tt.addr, got, tt.key)
76
func ResetProxyEnv() {
77
for _, v := range []string{"HTTP_PROXY", "http_proxy", "NO_PROXY", "no_proxy"} {
80
ResetCachedEnvironment()