From d9cdae33987047ab0d066b0c46edaec47cf993ec Mon Sep 17 00:00:00 2001 From: Sergey Frolov Date: Fri, 18 Aug 2017 11:34:52 -0400 Subject: [PATCH] go vet fixes --- common_test.go | 4 ++-- forwardproxy.go | 2 +- forwardproxy_test.go | 4 ++-- setup.go | 11 +++++++++-- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/common_test.go b/common_test.go index 116ff94..8134f1c 100644 --- a/common_test.go +++ b/common_test.go @@ -194,7 +194,7 @@ func TestTheTest(t *testing.T) { if err != nil { t.Fatal(err) } else if resp.StatusCode != http.StatusNotFound { - t.Fatalf("Expected: 404 StatusNotFound, got %s. Response: %#v\n", resp.StatusCode, resp) + t.Fatalf("Expected: 404 StatusNotFound, got %d. Response: %#v\n", resp.StatusCode, resp) } } @@ -202,7 +202,7 @@ func TestIsSubdomain(t *testing.T) { testSubDomain := func(s, domain string, expectedResult bool) { result := isSubdomain(s, domain) if result != expectedResult { - t.Fatalf("Expected: isSubdomain(%s, %s) is %b, Got: %b", s, domain, expectedResult, result) + t.Fatalf("Expected: isSubdomain(%s, %s) is %v, Got: %v", s, domain, expectedResult, result) } } testSubDomain("hoooli.abc", "hooya.ya", false) diff --git a/forwardproxy.go b/forwardproxy.go index f721df8..56792e4 100644 --- a/forwardproxy.go +++ b/forwardproxy.go @@ -50,7 +50,7 @@ var bufferPool sync.Pool // TODO?: getStatusCode(err) that casts to http.Error, net Error, etc. and returns correct http status code -func (fp ForwardProxy) connectPortIsAllowed(port string) bool { +func (fp *ForwardProxy) connectPortIsAllowed(port string) bool { portInt, err := strconv.Atoi(port) if err != nil { return false diff --git a/forwardproxy_test.go b/forwardproxy_test.go index ec9c4ac..30564ac 100644 --- a/forwardproxy_test.go +++ b/forwardproxy_test.go @@ -27,9 +27,9 @@ import ( "net" "net/http" "net/url" + "strings" "testing" "time" - "strings" ) func dial(proxyAddr string, useTls bool) (net.Conn, error) { @@ -188,7 +188,7 @@ func TestPassthrough(t *testing.T) { if err != nil { t.Fatal(err) } else if resp.StatusCode != http.StatusNotFound { - t.Fatalf("Expected: 404 StatusNotFound, got %s. Response: %#v\n", resp.StatusCode, resp) + t.Fatalf("Expected: 404 StatusNotFound, got %d. Response: %#v\n", resp.StatusCode, resp) } } diff --git a/setup.go b/setup.go index f22de24..31ef710 100644 --- a/setup.go +++ b/setup.go @@ -30,8 +30,15 @@ import ( func setup(c *caddy.Controller) error { httpserver.GetConfig(c).FallbackSite = true - fp := &ForwardProxy{dialTimeout: time.Second * 20, httpTransport: *http.DefaultTransport.(*http.Transport), - hostname: httpserver.GetConfig(c).Host(), port: httpserver.GetConfig(c).Port()} + fp := &ForwardProxy{dialTimeout: time.Second * 20, + hostname: httpserver.GetConfig(c).Host(), port: httpserver.GetConfig(c).Port(), + httpTransport: http.Transport{ + Proxy: http.ProxyFromEnvironment, + MaxIdleConns: 100, + IdleConnTimeout: 90 * time.Second, + TLSHandshakeTimeout: 10 * time.Second, + ExpectContinueTimeout: 1 * time.Second, + }} fp.httpTransport.DialTLS = func(network, addr string) (net.Conn, error) { return nil, &http.ProtocolError{ErrorString: "Proxy does not fetch TLS resources, use CONNECT instead"} }