Index: src/pkg/net/http/transport_test.go |
=================================================================== |
--- a/src/pkg/net/http/transport_test.go |
+++ b/src/pkg/net/http/transport_test.go |
@@ -16,6 +16,7 @@ |
. "net/http" |
"net/http/httptest" |
"net/url" |
+ "os" |
"runtime" |
"strconv" |
"strings" |
@@ -727,6 +728,36 @@ |
} |
} |
+var proxyFromEnvTests = []struct { |
+ env string |
+ wanturl string |
+ wanterr error |
+}{ |
+ {"127.0.0.1:8080", "http://127.0.0.1:8080", nil}, |
+ {"http://127.0.0.1:8080", "http://127.0.0.1:8080", nil}, |
+ {"https://127.0.0.1:8080", "https://127.0.0.1:8080", nil}, |
+ {"", "<nil>", nil}, |
+} |
+ |
+func TestProxyFromEnvironment(t *testing.T) { |
+ os.Setenv("HTTP_PROXY", "") |
+ os.Setenv("http_proxy", "") |
+ os.Setenv("NO_PROXY", "") |
+ os.Setenv("no_proxy", "") |
+ for i, tt := range proxyFromEnvTests { |
+ os.Setenv("HTTP_PROXY", tt.env) |
+ req, _ := NewRequest("GET", "http://example.com", nil) |
+ url, err := ProxyFromEnvironment(req) |
+ if g, e := fmt.Sprintf("%v", err), fmt.Sprintf("%v", tt.wanterr); g != e { |
+ t.Errorf("%d. got error = %q, want %q", i, g, e) |
+ continue |
+ } |
+ if got := fmt.Sprintf("%s", url); got != tt.wanturl { |
+ t.Errorf("%d. got URL = %q, want %q", i, url, tt.wanturl) |
+ } |
+ } |
+} |
+ |
// rgz is a gzip quine that uncompresses to itself. |
var rgz = []byte{ |
0x1f, 0x8b, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, |