From e4953d58765b1d921b57f5d8760985509be8e310 Mon Sep 17 00:00:00 2001 From: elij Date: Sun, 20 Aug 2023 21:01:05 -0700 Subject: [PATCH] slight optimization --- pkg/camo/proxy.go | 5 +++-- pkg/router/router.go | 3 +-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/camo/proxy.go b/pkg/camo/proxy.go index c6de6b2..b967368 100644 --- a/pkg/camo/proxy.go +++ b/pkg/camo/proxy.go @@ -90,7 +90,8 @@ func (p *Proxy) ServeHTTP(w http.ResponseWriter, req *http.Request) { // split path and get components components := strings.Split(req.URL.Path, "/") - if len(components) < 3 { + compLen := len(components) + if compLen < 3 { http.Error(w, "Malformed request path", http.StatusNotFound) return } @@ -102,7 +103,7 @@ func (p *Proxy) ServeHTTP(w http.ResponseWriter, req *http.Request) { } encodedExtraHdr := "" - if p.config.EnableExtraHeaders && len(components) == 4 { + if p.config.EnableExtraHeaders && compLen == 4 { encodedExtraHdr = components[3] } diff --git a/pkg/router/router.go b/pkg/router/router.go index 9feeb9f..fd36800 100644 --- a/pkg/router/router.go +++ b/pkg/router/router.go @@ -47,8 +47,7 @@ func (dr *DumbRouter) ServeHTTP(w http.ResponseWriter, r *http.Request) { return } - components := strings.Split(r.URL.Path, "/") - compLen := len(components) + compLen := strings.Count(r.URL.Path, "/") if compLen == 3 || compLen == 4 { dr.CamoHandler.ServeHTTP(w, r) return