Skip to content

Commit 64ae46c

Browse files
committed
use regexp for browser user-agent matching
1 parent 847fbe4 commit 64ae46c

File tree

1 file changed

+3
-10
lines changed
  • packages/orchestrator/internal/proxy

1 file changed

+3
-10
lines changed

packages/orchestrator/internal/proxy/proxy.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"net/http"
1414
"net/http/httputil"
1515
"net/url"
16+
"regexp"
1617
"strconv"
1718
"strings"
1819
"time"
@@ -21,8 +22,7 @@ import (
2122
//go:embed proxy_browser_502.html
2223
var proxyBrowser502PageHtml string
2324

24-
var browserIdentityKeywords = []string{
25-
"mozilla", "chrome", "safari", "firefox", "edge", "opera", "msie",
25+
var browserRegex = regexp.MustCompile(`(?i)mozilla|chrome|safari|firefox|edge|opera|msie`)
2626
var browserTemplate = template.Must(template.New("template").Parse(proxyBrowser502PageHtml))
2727

2828
type htmlTemplateData struct {
@@ -191,12 +191,5 @@ func (p *SandboxProxy) buildJsonClosedPortError(sandboxId string, port uint64) [
191191
}
192192

193193
func (p *SandboxProxy) isBrowser(userAgent string) bool {
194-
userAgent = strings.ToLower(userAgent)
195-
for _, keyword := range browserIdentityKeywords {
196-
if strings.Contains(userAgent, keyword) {
197-
return true
198-
}
199-
}
200-
201-
return false
194+
return browserRegex.MatchString(userAgent)
202195
}

0 commit comments

Comments
 (0)