Skip to content

Commit

Permalink
Refactored some naming
Browse files Browse the repository at this point in the history
  • Loading branch information
pspieker-stripe committed Jul 2, 2024
1 parent 529f11a commit 72d7dbc
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions https.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,21 +120,21 @@ func (proxy *ProxyHttpServer) handleHttps(w http.ResponseWriter, r *http.Request
host += ":80"
}

var httpsProxyURL string = proxy.HttpsProxyAddr
var httpsProxyString string = proxy.HttpsProxyAddr
if r.Header.Get(PerRequestHTTPSProxyHeaderKey) != "" {
httpsProxyURL = r.Header.Get(PerRequestHTTPSProxyHeaderKey)
httpsProxyString = r.Header.Get(PerRequestHTTPSProxyHeaderKey)
}

httpsProxy, err := httpsProxyAddr(r.URL, httpsProxyURL)
httpsProxyString, err := httpsProxyAddr(r.URL, httpsProxyString)
if err != nil {
ctx.Warnf("Error configuring HTTPS proxy err=%q url=%q", err, r.URL.String())
}

var targetSiteCon net.Conn
if httpsProxy == "" {
if httpsProxyString == "" {
targetSiteCon, err = proxy.connectDialContext(ctx, "tcp", host)
} else {
targetSiteCon, err = proxy.connectDialProxyWithContext(ctx, httpsProxyURL, host)
targetSiteCon, err = proxy.connectDialProxyWithContext(ctx, httpsProxyString, host)
}
if err != nil {
httpError(proxyClient, ctx, err)
Expand Down Expand Up @@ -614,5 +614,10 @@ func httpsProxyAddr(reqURL *url.URL, httpsProxy string) (string, error) {
service = proxyURL.Scheme
}

return fmt.Sprintf("%s://%s:%s", proxyURL.Scheme, proxyURL.Hostname(), service), nil
hostname := proxyURL.Hostname()
if proxyURL.User.String() != "" {
hostname = proxyURL.User.String() + "@" + hostname
}

return fmt.Sprintf("%s://%s:%s", proxyURL.Scheme, hostname, service), nil
}

0 comments on commit 72d7dbc

Please sign in to comment.