From 673bc9cab57ba06b1388541063202567a24d42f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Matczuk?= Date: Wed, 20 Nov 2024 11:41:57 +0100 Subject: [PATCH] http proxy: make isLocalhost() case insensitive --- http_proxy.go | 6 ++++++ http_proxy_test.go | 1 + 2 files changed, 7 insertions(+) diff --git a/http_proxy.go b/http_proxy.go index 52a87c3d..3916c3f7 100644 --- a/http_proxy.go +++ b/http_proxy.go @@ -17,6 +17,7 @@ import ( "net/http" "net/url" "slices" + "strings" "time" "github.com/saucelabs/forwarder/hostsfile" @@ -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() @@ -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 } diff --git a/http_proxy_test.go b/http_proxy_test.go index 2d9577cb..60e0482e 100644 --- a/http_proxy_test.go +++ b/http_proxy_test.go @@ -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},