[http_tunnel] trim rough edges.

This commit is contained in:
ymmt2005 2016-03-09 23:23:35 +09:00
parent 4d0b2534e4
commit 322a89746a
2 changed files with 7 additions and 5 deletions

View File

@ -33,14 +33,14 @@ type httpDialer struct {
} }
func httpDialType(u *url.URL, forward proxy.Dialer) (proxy.Dialer, error) { func httpDialType(u *url.URL, forward proxy.Dialer) (proxy.Dialer, error) {
authz := "" var header http.Header
if uu := u.User; uu != nil { if uu := u.User; uu != nil {
passwd, _ := uu.Password() passwd, _ := uu.Password()
up := uu.Username() + ":" + passwd up := uu.Username() + ":" + passwd
authz = "Basic " + base64.StdEncoding.EncodeToString([]byte(up)) authz := "Basic " + base64.StdEncoding.EncodeToString([]byte(up))
} header = map[string][]string{
header := map[string][]string{ "Proxy-Authorization": []string{authz},
"Proxy-Authorization": []string{authz}, }
} }
return &httpDialer{ return &httpDialer{
addr: u.Host, addr: u.Host,

View File

@ -23,6 +23,8 @@ func TestHTTPDialer(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) 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")) 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) io.Copy(os.Stdout, conn)
} }