Skip to content

Commit

Permalink
fix: fix for upstream proxy authentication google#269
Browse files Browse the repository at this point in the history
  • Loading branch information
skiloop committed Oct 8, 2018
1 parent 412d6c6 commit 4f24560
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"sync"
"time"

"encoding/base64"
"github.com/google/martian/log"
"github.com/google/martian/mitm"
"github.com/google/martian/nosigpipe"
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 4f24560

Please sign in to comment.