diff options
| author | Fuwn <[email protected]> | 2025-07-08 04:50:54 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2025-07-08 04:50:54 +0000 |
| commit | 1776a876c1b032a4c9fa111f2d55b0656096c4cc (patch) | |
| tree | d55a54b567d0bf4e365f93b6917440e718849e9e /src/router.rs | |
| parent | feat(router): Add options system (diff) | |
| download | windmark-1776a876c1b032a4c9fa111f2d55b0656096c4cc.tar.xz windmark-1776a876c1b032a4c9fa111f2d55b0656096c4cc.zip | |
refactor(router): Smarter trailing slash clipper
Diffstat (limited to 'src/router.rs')
| -rw-r--r-- | src/router.rs | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/src/router.rs b/src/router.rs index 7584401..a82ea1e 100644 --- a/src/router.rs +++ b/src/router.rs @@ -51,7 +51,6 @@ use crate::{ module::{AsyncModule, Module}, response::Response, router_option::RouterOption, - utilities, }; macro_rules! block { @@ -421,13 +420,18 @@ impl Router { url.set_path("/"); } - let fixed_path = - if self.options.contains(&RouterOption::TrimTrailingSlashes) { - utilities::normalize_path_slashes(url.path()) - } else { - url.path().to_string() - }; - let route = &mut self.routes.at(&fixed_path); + let mut path = url.path().to_string(); + let mut route = self.routes.at(&path); + + if route.is_err() + && self.options.contains(&RouterOption::TrimTrailingSlashes) + && path.ends_with('/') + && path != "/" + { + path = path.trim_end_matches('/').to_string(); + route = self.routes.at(&path); + } + let peer_certificate = stream.ssl().peer_certificate(); let hook_context = HookContext::new( stream.get_ref().peer_addr(), |