From 4f245600e7c97e0338cd30260a8521b830bd3880 Mon Sep 17 00:00:00 2001 From: shibaofeng Date: Mon, 8 Oct 2018 17:09:43 +0800 Subject: [PATCH 1/2] fix: fix for upstream proxy authentication #269 --- proxy.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/proxy.go b/proxy.go index 57a221cb3..5deacb29b 100644 --- a/proxy.go +++ b/proxy.go @@ -28,6 +28,7 @@ import ( "sync" "time" + "encoding/base64" "github.com/google/martian/log" "github.com/google/martian/mitm" "github.com/google/martian/nosigpipe" @@ -558,15 +559,22 @@ func (p *Proxy) connect(req *http.Request) (*http.Response, net.Conn, error) { } pbw := bufio.NewWriter(conn) pbr := bufio.NewReader(conn) - + r := new(http.Request) + *r = *req + r.Header.Del("Proxy-Authorization") + if p.proxyURL.User != nil { + r.Header.Add("Proxy-Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte(p.proxyURL.User.String()))) + } req.Write(pbw) pbw.Flush() - res, err := http.ReadResponse(pbr, req) + res, err := http.ReadResponse(pbr, r) if err != nil { return nil, nil, err } - + if res.StatusCode == 200 { + return proxyutil.NewResponse(200, nil, r), conn, nil + } return res, conn, nil } From 6fbd807febfc8239eb5d5de1c0752622b78db60c Mon Sep 17 00:00:00 2001 From: shibaofeng Date: Tue, 30 Oct 2018 15:58:51 +0800 Subject: [PATCH 2/2] style: reformat code --- proxy.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proxy.go b/proxy.go index a0cc07059..d2c095d15 100644 --- a/proxy.go +++ b/proxy.go @@ -593,4 +593,4 @@ func (p *Proxy) connect(req *http.Request) (*http.Response, net.Conn, error) { } return proxyutil.NewResponse(200, nil, req), conn, nil -} \ No newline at end of file +}