Skip to content

Commit 00bec2d

Browse files
Added test stub and PR feedback responses
1 parent 72d7dbc commit 00bec2d

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

https.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -544,19 +544,21 @@ func (proxy *ProxyHttpServer) connectDialProxyWithContext(ctx *ProxyCtx, proxyHo
544544
c = tls.Client(c, proxy.Tr.TLSClientConfig)
545545
}
546546

547-
hdr := make(http.Header)
547+
connectRequestHeaders := make(http.Header)
548548

549-
// Add proxy authentication header if needed
550-
auth := proxyURL.User.String()
551-
if auth != "" {
552-
hdr.Add("Proxy-Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte(auth)))
549+
// Add authentication header if needed to the CONNECT request to the proxy
550+
user := proxyURL.User
551+
if user != nil {
552+
if auth := user.String(); auth != "" {
553+
connectRequestHeaders.Add("Proxy-Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte(auth)))
554+
}
553555
}
554556

555557
connectReq := &http.Request{
556558
Method: "CONNECT",
557559
URL: &url.URL{Opaque: host},
558560
Host: host,
559-
Header: hdr,
561+
Header: connectRequestHeaders,
560562
}
561563
connectReq.Write(c)
562564
// Read response.

proxy_test.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,12 @@ func TestOverrideHttpsProxyAddrsFromEnvWithRequest(t *testing.T) {
750750

751751
fakeExternalProxy := goproxy.NewProxyHttpServer()
752752
fakeExternalProxyTestStruct := httptest.NewServer(fakeExternalProxy)
753-
fakeExternalProxy.OnRequest().HandleConnect(goproxy.AlwaysMitm)
753+
var AlwaysMitmAndPassthrough goproxy.FuncHttpsHandler = func(host string, ctx *goproxy.ProxyCtx) (*goproxy.ConnectAction, string) {
754+
// TODO: make this test use the X-Https-Upstream-Proxy header and parse it out here to make sure it's set and passed through
755+
// to the authorization header
756+
return goproxy.MitmConnect, host
757+
}
758+
fakeExternalProxy.OnRequest().HandleConnect(AlwaysMitmAndPassthrough)
754759
tagExternalProxyPassthrough := func(resp *http.Response, ctx *goproxy.ProxyCtx) *http.Response {
755760
b, err := ioutil.ReadAll(resp.Body)
756761
panicOnErr(err, "readAll resp")

0 commit comments

Comments
 (0)