2012-03-27 23:13:14 +00:00
|
|
|
// Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package http
|
|
|
|
|
|
|
|
import (
|
2014-09-21 17:33:12 +00:00
|
|
|
"net/url"
|
2012-03-27 23:13:14 +00:00
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
// TODO(mattn):
|
|
|
|
// test ProxyAuth
|
|
|
|
|
2014-09-21 17:33:12 +00:00
|
|
|
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
|
|
|
|
}
|
2019-06-02 15:48:37 +00:00
|
|
|
cm := connectMethod{proxy, tt.scheme, tt.addr, false}
|
2015-08-28 15:33:40 +00:00
|
|
|
if got := cm.key().String(); got != tt.key {
|
|
|
|
t.Fatalf("{%q, %q, %q} cache key = %q; want %q", tt.proxy, tt.scheme, tt.addr, got, tt.key)
|
2014-09-21 17:33:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-08-28 15:33:40 +00:00
|
|
|
|
|
|
|
func ResetProxyEnv() {
|
2019-06-02 15:48:37 +00:00
|
|
|
for _, v := range []string{"HTTP_PROXY", "http_proxy", "NO_PROXY", "no_proxy", "REQUEST_METHOD"} {
|
2018-12-28 15:30:48 +00:00
|
|
|
os.Unsetenv(v)
|
2015-08-28 15:33:40 +00:00
|
|
|
}
|
|
|
|
ResetCachedEnvironment()
|
|
|
|
}
|