defer mux.mu.RUnlock()
n, matches := mux.tree.match(host, method, path)
- // If we have an exact match, or we were asked not to try trailing-slash redirection,
- // or the URL already has a trailing slash, then we're done.
- if !exactMatch(n, path) && u != nil && !strings.HasSuffix(path, "/") {
+ // We can terminate here if any of the following is true:
+ // - We have an exact match already.
+ // - We were asked not to try trailing slash redirection.
+ // - The URL already has a trailing slash.
+ // - The URL is an empty string.
+ if !exactMatch(n, path) && u != nil && !strings.HasSuffix(path, "/") && path != "" {
// If there is an exact match with a trailing slash, then redirect.
path += "/"
n2, _ := mux.tree.match(host, method, path)
{"GET", "/foo/x", "&http.handler{i:2}"},
{"GET", "/bar/x", "&http.handler{i:4}"},
{"GET", "/bar", `&http.redirectHandler{url:"/bar/", code:301}`},
+ {"CONNECT", "", "(http.HandlerFunc)(.*)"},
{"CONNECT", "/", "&http.handler{i:1}"},
{"CONNECT", "//", "&http.handler{i:1}"},
{"CONNECT", "//foo", "&http.handler{i:5}"},
r.URL = &url.URL{Path: test.path}
gotH, _, _, _ := mux.findHandler(&r)
got := fmt.Sprintf("%#v", gotH)
- if got != test.wantHandler {
+ if !regexp.MustCompile(test.wantHandler).MatchString(got) {
t.Errorf("%s %q: got %q, want %q", test.method, test.path, got, test.wantHandler)
}
}