Skip to content

Commit

Permalink
Added test stub and PR feedback responses
Browse files Browse the repository at this point in the history
  • Loading branch information
pspieker-stripe committed Jul 5, 2024
1 parent 72d7dbc commit 00bec2d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
14 changes: 8 additions & 6 deletions https.go
Original file line number Diff line number Diff line change
Expand Up @@ -544,19 +544,21 @@ func (proxy *ProxyHttpServer) connectDialProxyWithContext(ctx *ProxyCtx, proxyHo
c = tls.Client(c, proxy.Tr.TLSClientConfig)
}

hdr := make(http.Header)
connectRequestHeaders := make(http.Header)

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

connectReq := &http.Request{
Method: "CONNECT",
URL: &url.URL{Opaque: host},
Host: host,
Header: hdr,
Header: connectRequestHeaders,
}
connectReq.Write(c)
// Read response.
Expand Down
7 changes: 6 additions & 1 deletion proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,12 @@ func TestOverrideHttpsProxyAddrsFromEnvWithRequest(t *testing.T) {

fakeExternalProxy := goproxy.NewProxyHttpServer()
fakeExternalProxyTestStruct := httptest.NewServer(fakeExternalProxy)
fakeExternalProxy.OnRequest().HandleConnect(goproxy.AlwaysMitm)
var AlwaysMitmAndPassthrough goproxy.FuncHttpsHandler = func(host string, ctx *goproxy.ProxyCtx) (*goproxy.ConnectAction, string) {
// 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
// to the authorization header
return goproxy.MitmConnect, host
}
fakeExternalProxy.OnRequest().HandleConnect(AlwaysMitmAndPassthrough)
tagExternalProxyPassthrough := func(resp *http.Response, ctx *goproxy.ProxyCtx) *http.Response {
b, err := ioutil.ReadAll(resp.Body)
panicOnErr(err, "readAll resp")
Expand Down

0 comments on commit 00bec2d

Please sign in to comment.