diff --git a/dispatcher.go b/dispatcher.go index 49c267d7..34af5d78 100644 --- a/dispatcher.go +++ b/dispatcher.go @@ -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)