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
Routes, named params and case sensitivity #1
Comments
Except for the domain name portion URLs are case-sensitive as defined in the RFC. But this is interesting thought. It would be possible to add a parameter to globally (for all routes) make the routing case insensitive by just applying Any other ideas? |
Sorry, I missed your last sentence. Just applying |
It could work if But this would still rely on a per-router setting, is that acceptable? |
Just to clarify. Such a setting would be per-router, thus affecting all routes defined for a particular router instance? I would have no problem with that. I understand your point about URL RFC compliance, but that doesn't help with end users that type what they want. :) Thanks for the consideration. |
Exactly. Also using both |
Ok, thanks! |
In addition to this, a global option to force everything to lower, including named params as you mention above would be nice as well. Understanding of course that it will violate RFC compliance if turned on. Something like: httprouter.NormalizePathsToLower = true And then here adding: if NormalizePathsToLower {
path = strings.ToLower(path)
} PS: I'd be happy to submit a PR. |
This took longer and was a lot harder to implement than I hoped... Instead of case-insensitive routes the router now supports the automatic redirection of routes having wrong cases. I think this is better since it doesn't introduce duplicate URLs ( The router does now the following (if not configured otherwise):
If you only have lowercase routes, this normalizes all request paths to lowercase as requested by @jmervine. But it uses a 301 permanent redirection instead of silently accepting the wrong URL 😃 (better for SEO etc.). |
tl;dr: The behavior described by @kpowick in the first post is now default, without any additional configuration. |
Nice! Excellent solution. |
Provide basic setup
Am I correct in assuming that the design that allows for quick route matching also restricts the routes themselves to being case sensitive?
e.g. For the given route with a named paramter
Is there any way to always return
Hello Joe
for the following requests?i.e. The desire is to have the route be case insensitive with the values of named parameters retaining their casing.
The text was updated successfully, but these errors were encountered: