Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix prefix match #591

Merged
merged 1 commit into from
Dec 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading