Skip to content

Commit

Permalink
Improve the https scheme matching (#508)
Browse files Browse the repository at this point in the history
Improve the https scheme matching

---------

Co-authored-by: Erik Pellizzon <[email protected]>
  • Loading branch information
ryoii and ErikPelli authored Dec 16, 2024
1 parent 033b654 commit e85c60b
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions https.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"net/http"
"net/url"
"os"
"regexp"
"strconv"
"strings"
"sync"
Expand All @@ -34,7 +33,6 @@ var (
MitmConnect = &ConnectAction{Action: ConnectMitm, TLSConfig: TLSConfigFromCA(&GoproxyCa)}
HTTPMitmConnect = &ConnectAction{Action: ConnectHTTPMitm, TLSConfig: TLSConfigFromCA(&GoproxyCa)}
RejectConnect = &ConnectAction{Action: ConnectReject, TLSConfig: TLSConfigFromCA(&GoproxyCa)}
httpsRegexp = regexp.MustCompile(`^https:\/\/`)
)

// ConnectAction enables the caller to override the standard connect flow.
Expand Down Expand Up @@ -232,7 +230,7 @@ func (proxy *ProxyHttpServer) handleHttps(w http.ResponseWriter, r *http.Request
req.RemoteAddr = r.RemoteAddr // since we're converting the request, need to carry over the original connecting IP as well
ctx.Logf("req %v", r.Host)

if !httpsRegexp.MatchString(req.URL.String()) {
if !strings.HasPrefix(req.URL.String(), "https://") {
req.URL, err = url.Parse("https://" + r.Host + req.URL.String())
}

Expand Down

0 comments on commit e85c60b

Please sign in to comment.