aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2025-07-08 05:30:21 +0000
committerFuwn <[email protected]>2025-07-08 05:30:21 +0000
commit6544d0dc7762b3ddf5d59db68629f2bd4a55650f (patch)
tree9523cccc017225cffdd599e930efb2e518eae285
parentdocs(router_option): Expand documentation (diff)
downloadwindmark-6544d0dc7762b3ddf5d59db68629f2bd4a55650f.tar.xz
windmark-6544d0dc7762b3ddf5d59db68629f2bd4a55650f.zip
feat(router): Add case-insensitive route matching option
-rw-r--r--examples/fix_path.rs7
-rw-r--r--src/router.rs8
-rw-r--r--src/router_option.rs3
3 files changed, 16 insertions, 2 deletions
diff --git a/examples/fix_path.rs b/examples/fix_path.rs
index 6ea8f9e..f0be8f7 100644
--- a/examples/fix_path.rs
+++ b/examples/fix_path.rs
@@ -17,14 +17,17 @@
//! `cargo run --example fix_path --features response-macros`
+use windmark::router_option::RouterOption;
+
#[windmark::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
windmark::router::Router::new()
.set_private_key_file("windmark_private.pem")
.set_certificate_file("windmark_public.pem")
.add_options(&[
- windmark::router_option::RouterOption::RemoveExtraTrailingSlash,
- windmark::router_option::RouterOption::AddMissingTrailingSlash,
+ RouterOption::RemoveExtraTrailingSlash,
+ RouterOption::AddMissingTrailingSlash,
+ RouterOption::AllowCaseInsensitiveLookup,
])
.mount(
"/close",
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,
}