From 1776a876c1b032a4c9fa111f2d55b0656096c4cc Mon Sep 17 00:00:00 2001 From: Fuwn Date: Tue, 8 Jul 2025 04:50:54 +0000 Subject: refactor(router): Smarter trailing slash clipper --- src/router.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'src/router.rs') 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(), -- cgit v1.2.3