Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Non-wildcard routes that share a prefix with a wildcard route should take priority over the wildcard route #73
Currently it is impossible to do the following with httprouter:
router := httprouter.New() router.Handle("GET", "/*path", proxy) router.Handle("GET", "/api", api)
This makes it impossible to do "enhanced" proxies and CMS'es that have completely dynamic URL's other than a control panel, just to name two practical examples.
To address this, I propose that URL's that share prefixes with wildcards would take priority over the wildcard. Effectively, they would have a higher weight. This is how I solved a similar problem in the Werkzeug WSGI library for Python.
In the above example, /api would take priority because it has a non-wildcard component in the same place as another route with a wildcard.
Combined with #72, this would also dramatically improve the ability to compose packages with httprouter.
No, let me cite you from the README:
The special treatment of
I'm sorry but "makes it great for SEO and improves the user experience"?
First off, It has absolutely nothing to do with SEO, I don't know where you even got that idea.
Second, a user now has to apply middleware or use the
Defining wildcards as being fallbacks when there isn't an exact match gives a much more flexible API, much like the change I made in #72 for HTTP methods. It does not clutter or confuse the API.
I just came across this problem and found this issue, so am replying here.
Can you suggest a way that it might be possible to continue to use httprouter for
For example, if we wanted to serve something like this, with the
Your suggestion, I think, would be to make a custom handler
Looking at this and my code again, my needs might be a bit different. I need these two routes to play nicely with each other:
I was surprised to see this panic:
because, from the docs:
I would have expected
Still kind of new to this router... maybe this is a separate issue?