httptreemux
httptreemux copied to clipboard
wildcard route "/*" doesn't match "/"
A wildcard path handler for /*
does not match an empty path (i.e. /
). There doesn't seem to be any way to match all paths, including the empty path (since all paths are required to start with /
).
https://go.dev/play/p/-frMTiD_l1R
import (
"fmt"
"net/http"
"net/url"
"github.com/dimfeld/httptreemux"
)
func main() {
router := httptreemux.New()
router.Handle(http.MethodPost, "/*", func(w http.ResponseWriter, r *http.Request, m map[string]string) {
w.WriteHeader(http.StatusOK)
})
request := http.Request{
URL: &url.URL{
Scheme: "http",
Host: "localhost",
Path: "/",
},
RequestURI: "/",
Method: http.MethodPost,
}
_, ok := router.Lookup(nil, &request)
if ok {
fmt.Println("found a route")
} else {
fmt.Println("no route found")
}
}
Expected: "found a route" Actual: "no route found"