middlewares / ideas

Need a Middleware or looking for ideas?
5 stars 0 forks source link

Case insensitive URI #28

Closed mav2287 closed 3 years ago

mav2287 commented 3 years ago

Not sure if this is already available, but a middleware that would make routes case insensitive could be useful. I ran into this recently with a route that I named "oAuth", but later tried to access using "oauth".

oscarotero commented 3 years ago

Good idea. Do you like to work on this?

mav2287 commented 3 years ago

I can put something together.

In terms of implementing it, the only way that occurred to me to handle this was to make the URI path lower case. However, the routes are feed into the router middleware I haven't been able to come up with a good way to make the actual route declarations lowercase. Do you have any thoughts on the best way to handle that?

oscarotero commented 3 years ago

To me, both things are different. An user may want to convert the url to lowercase because the routes patterns are lowercase too, and this ensures that /api/users and /api/Users returns the same response. But the responsability of this middleware should be only to convert the uri path to lowercase, no matter what other middlewares can come later.

mav2287 commented 3 years ago

That makes sense. If you take a look at this issue filed on the fast-route page, https://github.com/slimphp/Slim/issues/2383#issuecomment-620330139, the sample code is fairly close to what I was thinking. He even has an option to redirect to the lowercase route which I think makes sense. If you agree that is right direction and want to create an empty repo I put the code together in the next few days for this.

oscarotero commented 3 years ago

There's a skeleton package to create new middlewares easily: https://github.com/middlewares/skeleton Just need to run this command: composer create-project middlewares/skeleton my-middleware (replacing my-middleware with the name of the new middleware).

I just created a new repo using the skeleton as the base template: https://github.com/middlewares/lowercase

mav2287 commented 3 years ago

Closing since the Middleware for this is now available at https://github.com/middlewares/lowercase