Skip to content

Commit

Permalink
slight optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
dropwhile committed Aug 21, 2023
1 parent 818f08b commit e4953d5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
5 changes: 3 additions & 2 deletions pkg/camo/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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]
}

Expand Down
3 changes: 1 addition & 2 deletions pkg/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e4953d5

Please sign in to comment.