Skip to content

Commit

Permalink
Fix prefix match (#591)
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikPelli authored Dec 21, 2024
1 parent 07776d9 commit 65f394b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,14 @@ func (c RespConditionFunc) HandleResp(resp *http.Response, ctx *ProxyCtx) bool {
// requests to url 'http://host/x'
func UrlHasPrefix(prefix string) ReqConditionFunc {
return func(req *http.Request, ctx *ProxyCtx) bool {
// Make sure to include the / as the first path character
// Make sure to include the / as the first path character when we do a match
// using the host
relativePath := req.URL.Path
if length := len(relativePath); length == 0 || (length > 0 && relativePath[0] != '/') {
relativePath = "/" + relativePath
}
return strings.HasPrefix(relativePath, prefix) ||
// We use the original value to distinguish between "" and "/" in the user specified string
return strings.HasPrefix(req.URL.Path, prefix) ||
strings.HasPrefix(req.URL.Host+relativePath, prefix) ||
// Scheme value is something like "https", we must include the :// characters
strings.HasPrefix(req.URL.Scheme+"://"+req.URL.Host+relativePath, prefix)
Expand Down

0 comments on commit 65f394b

Please sign in to comment.