Skip to content

Commit e97df6b

Browse files
committed
feat(router): Add case-insensitive route matching option
1 parent 4af8167 commit e97df6b

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

examples/fix_path.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,17 @@
1717

1818
//! `cargo run --example fix_path --features response-macros`
1919
20+
use windmark::router_option::RouterOption;
21+
2022
#[windmark::main]
2123
async fn main() -> Result<(), Box<dyn std::error::Error>> {
2224
windmark::router::Router::new()
2325
.set_private_key_file("windmark_private.pem")
2426
.set_certificate_file("windmark_public.pem")
2527
.add_options(&[
26-
windmark::router_option::RouterOption::RemoveExtraTrailingSlash,
27-
windmark::router_option::RouterOption::AddMissingTrailingSlash,
28+
RouterOption::RemoveExtraTrailingSlash,
29+
RouterOption::AddMissingTrailingSlash,
30+
RouterOption::AllowCaseInsensitiveLookup,
2831
])
2932
.mount(
3033
"/close",

src/router.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,14 @@ impl Router {
421421
}
422422

423423
let mut path = url.path().to_string();
424+
425+
if self
426+
.options
427+
.contains(&RouterOption::AllowCaseInsensitiveLookup)
428+
{
429+
path = path.to_lowercase();
430+
}
431+
424432
let mut route = self.routes.at(&path);
425433

426434
if route.is_err() {

src/router_option.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,7 @@ pub enum RouterOption {
77
/// If enabled, adds a trailing slash to the request URL path if a route
88
/// exists for the path with the slash (e.g., `/foo` becomes `/foo/`).
99
AddMissingTrailingSlash,
10+
/// If enabled, the router will perform case-insensitive matching for
11+
/// incoming request URL paths (e.g., `/foo` will match `/Foo` or `/FOO`).
12+
AllowCaseInsensitiveLookup,
1013
}

0 commit comments

Comments
 (0)