PageRenderTime 7ms CodeModel.GetById 1ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/http/proxy_test.go

http://github.com/petar/GoHTTP
Go | 48 lines | 34 code | 8 blank | 6 comment | 3 complexity | 19dd20a2bb5836acd29bb9243cb67e00 MD5 | raw file
 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
 5package http
 6
 7import (
 8	"os"
 9	"testing"
10)
11
12// TODO(mattn):
13//	test ProxyAuth
14
15var UseProxyTests = []struct {
16	host  string
17	match bool
18}{
19	// Never proxy localhost:
20	{"localhost:80", false},
21	{"127.0.0.1", false},
22	{"127.0.0.2", false},
23	{"[::1]", false},
24	{"[::2]", true}, // not a loopback address
25
26	{"barbaz.net", false},     // match as .barbaz.net
27	{"foobar.com", false},     // have a port but match 
28	{"foofoobar.com", true},   // not match as a part of foobar.com
29	{"baz.com", true},         // not match as a part of barbaz.com
30	{"localhost.net", true},   // not match as suffix of address
31	{"local.localhost", true}, // not match as prefix as address
32	{"barbarbaz.net", true},   // not match because NO_PROXY have a '.'
33	{"www.foobar.com", true},  // not match because NO_PROXY is not .foobar.com
34}
35
36func TestUseProxy(t *testing.T) {
37	oldenv := os.Getenv("NO_PROXY")
38	defer os.Setenv("NO_PROXY", oldenv)
39
40	no_proxy := "foobar.com, .barbaz.net"
41	os.Setenv("NO_PROXY", no_proxy)
42
43	for _, test := range UseProxyTests {
44		if useProxy(test.host+":80") != test.match {
45			t.Errorf("useProxy(%v) = %v, want %v", test.host, !test.match, test.match)
46		}
47	}
48}