From 6544d0dc7762b3ddf5d59db68629f2bd4a55650f Mon Sep 17 00:00:00 2001 From: Fuwn Date: Tue, 8 Jul 2025 05:30:21 +0000 Subject: feat(router): Add case-insensitive route matching option --- src/router.rs | 8 ++++++++ src/router_option.rs | 3 +++ 2 files changed, 11 insertions(+) (limited to 'src') diff --git a/src/router.rs b/src/router.rs index 6ae33b0..81eb6c4 100644 --- a/src/router.rs +++ b/src/router.rs @@ -421,6 +421,14 @@ impl Router { } let mut path = url.path().to_string(); + + if self + .options + .contains(&RouterOption::AllowCaseInsensitiveLookup) + { + path = path.to_lowercase(); + } + let mut route = self.routes.at(&path); if route.is_err() { diff --git a/src/router_option.rs b/src/router_option.rs index 62ecb47..a28ba6f 100644 --- a/src/router_option.rs +++ b/src/router_option.rs @@ -7,4 +7,7 @@ pub enum RouterOption { /// If enabled, adds a trailing slash to the request URL path if a route /// exists for the path with the slash (e.g., `/foo` becomes `/foo/`). AddMissingTrailingSlash, + /// If enabled, the router will perform case-insensitive matching for + /// incoming request URL paths (e.g., `/foo` will match `/Foo` or `/FOO`). + AllowCaseInsensitiveLookup, } -- cgit v1.2.3