Skip to content

Commit

Permalink
Add Proxy-Authorization header support for URL encoded credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
pspieker-stripe committed Jul 2, 2024
1 parent 560c3ba commit 529f11a
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions https.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"bytes"
"context"
"crypto/tls"
"encoding/base64"
"errors"
"fmt"
"io"
Expand Down Expand Up @@ -133,7 +134,7 @@ func (proxy *ProxyHttpServer) handleHttps(w http.ResponseWriter, r *http.Request
if httpsProxy == "" {
targetSiteCon, err = proxy.connectDialContext(ctx, "tcp", host)
} else {
targetSiteCon, err = proxy.connectDialProxyWithContext(ctx, httpsProxy, host)
targetSiteCon, err = proxy.connectDialProxyWithContext(ctx, httpsProxyURL, host)
}
if err != nil {
httpError(proxyClient, ctx, err)
Expand Down Expand Up @@ -543,11 +544,19 @@ func (proxy *ProxyHttpServer) connectDialProxyWithContext(ctx *ProxyCtx, proxyHo
c = tls.Client(c, proxy.Tr.TLSClientConfig)
}

hdr := 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)))
}

connectReq := &http.Request{
Method: "CONNECT",
URL: &url.URL{Opaque: host},
Host: host,
Header: make(http.Header),
Header: hdr,
}
connectReq.Write(c)
// Read response.
Expand Down

0 comments on commit 529f11a

Please sign in to comment.