diff --git a/http_tunnel.go b/http_tunnel.go index aefb68f..2d64f39 100644 --- a/http_tunnel.go +++ b/http_tunnel.go @@ -33,14 +33,14 @@ type httpDialer struct { } func httpDialType(u *url.URL, forward proxy.Dialer) (proxy.Dialer, error) { - authz := "" + var header http.Header if uu := u.User; uu != nil { passwd, _ := uu.Password() up := uu.Username() + ":" + passwd - authz = "Basic " + base64.StdEncoding.EncodeToString([]byte(up)) - } - header := map[string][]string{ - "Proxy-Authorization": []string{authz}, + authz := "Basic " + base64.StdEncoding.EncodeToString([]byte(up)) + header = map[string][]string{ + "Proxy-Authorization": []string{authz}, + } } return &httpDialer{ addr: u.Host, diff --git a/http_tunnel_test.go b/http_tunnel_test.go index 69d4131..bfedd0f 100644 --- a/http_tunnel_test.go +++ b/http_tunnel_test.go @@ -23,6 +23,8 @@ func TestHTTPDialer(t *testing.T) { if err != nil { t.Fatal(err) } + defer conn.Close() + conn.Write([]byte("GET / HTTP/1.1\r\nHost: www.yahoo.com:80\r\nConnection: close\r\n\r\n")) io.Copy(os.Stdout, conn) }