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

wildcard route "/*" doesn't match "/" #95

Open
bionoren opened this issue Jul 9, 2024 · 1 comment
Open

wildcard route "/*" doesn't match "/" #95

bionoren opened this issue Jul 9, 2024 · 1 comment

Comments

@bionoren
Copy link

bionoren commented Jul 9, 2024

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"

@dimfeld
Copy link
Owner

dimfeld commented Jul 10, 2024

Hey, thanks for filing the issue and for the reproduction. Unfortunately I actually haven't been maintaining this library or even using Go for a few years now, so my recommendation would probably be to find another router project that is still actively maintained.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants