Skip to content

Commit

Permalink
http proxy: make isLocalhost() case insensitive
Browse files Browse the repository at this point in the history
  • Loading branch information
mmatczuk committed Nov 20, 2024
1 parent fe67efc commit 673bc9c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
6 changes: 6 additions & 0 deletions http_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"net/http"
"net/url"
"slices"
"strings"
"time"

"github.com/saucelabs/forwarder/hostsfile"
Expand Down Expand Up @@ -176,6 +177,9 @@ func NewHTTPProxy(cfg *HTTPProxyConfig, pr PACResolver, cm *CredentialsMatcher,
if err != nil {
return nil, fmt.Errorf("read localhost aliases: %w", err)
}
for i := range lh {
lh[i] = strings.ToLower(lh[i])
}
hp.localhost = append(hp.localhost, lh...)

ll, err := hp.listen()
Expand Down Expand Up @@ -466,6 +470,8 @@ func (hp *HTTPProxy) directLocalhost(fn ProxyFunc) ProxyFunc {
}

func (hp *HTTPProxy) isLocalhost(host string) bool {
host = strings.ToLower(host)

if slices.Contains(hp.localhost, host) {
return true
}
Expand Down
1 change: 1 addition & 0 deletions http_proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ func TestIsLocalhost(t *testing.T) {
{"127.0.0.1", true},
{"127.10.20.30", true},
{"localhost", true},
{"LOCALHOST", true},
{"0.0.0.0", true},

{"notlocalhost", false},
Expand Down

0 comments on commit 673bc9c

Please sign in to comment.