martenframework / marten

The pragmatic web framework.
https://martenframework.com
MIT License
405 stars 23 forks source link

Add new trailing slash control settings #128

Closed ellmetha closed 3 months ago

ellmetha commented 10 months ago

Description

Let's introduce a new routing.append_slash setting in order to make it possible to configure that an HTTP redirect should be issued for any incoming URL that does not resolve to any routes in case it does not end with a slash. The HTTP redirect should target the same URL but with a slash appended. The reasoning behind that is it helps in normalizing routes and URLs, by enforcing the use of canonical URLs.

The default value for this new setting should be false. The redirect implementation should probably live in the internal Marten::Server::Handlers::Routing server handler.

itsayopapi commented 10 months ago

@ellmetha May i please work on this issue?

ellmetha commented 10 months ago

@itsayopapi yes feel free to work on it!

notramo commented 6 months ago

It should support multiple use cases

Is there an actual use case for having separate routes which are the same and only differ in the trailing slash? If not, then I would recommend always redirecting to the configured value, not only in case it's not found. It helps the developer to consistently declare routes, e.g. it would prevent adding a route that does not follow project conventions.