🏗️ Elegant & Highly Performant Async Gemini Server Framework for the Modern Age
async framework gemini-protocol protocol gemini rust
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

refactor(router): Smarter trailing slash clipper

Fuwn 1776a876 215d8529

+12 -35
+12 -8
src/router.rs
··· 51 51 module::{AsyncModule, Module}, 52 52 response::Response, 53 53 router_option::RouterOption, 54 - utilities, 55 54 }; 56 55 57 56 macro_rules! block { ··· 421 420 url.set_path("/"); 422 421 } 423 422 424 - let fixed_path = 425 - if self.options.contains(&RouterOption::TrimTrailingSlashes) { 426 - utilities::normalize_path_slashes(url.path()) 427 - } else { 428 - url.path().to_string() 429 - }; 430 - let route = &mut self.routes.at(&fixed_path); 423 + let mut path = url.path().to_string(); 424 + let mut route = self.routes.at(&path); 425 + 426 + if route.is_err() 427 + && self.options.contains(&RouterOption::TrimTrailingSlashes) 428 + && path.ends_with('/') 429 + && path != "/" 430 + { 431 + path = path.trim_end_matches('/').to_string(); 432 + route = self.routes.at(&path); 433 + } 434 + 431 435 let peer_certificate = stream.ssl().peer_certificate(); 432 436 let hook_context = HookContext::new( 433 437 stream.get_ref().peer_addr(),
-27
src/utilities.rs
··· 40 40 .map(|(k, v)| (k.to_string(), v.to_string())) 41 41 .collect() 42 42 } 43 - 44 - /// Normalizes a path by removing all trailing slashes, unless it's the root 45 - /// path "/". 46 - /// 47 - /// # Examples 48 - /// 49 - /// ```rust 50 - /// assert_eq!( 51 - /// windmark::utilities::normalize_path_slashes("/foo///"), 52 - /// "/foo" 53 - /// ); 54 - /// assert_eq!(windmark::utilities::normalize_path_slashes("/foo/"), "/foo"); 55 - /// assert_eq!(windmark::utilities::normalize_path_slashes("/foo"), "/foo"); 56 - /// assert_eq!(windmark::utilities::normalize_path_slashes("/"), "/"); 57 - /// ``` 58 - #[must_use] 59 - pub fn normalize_path_slashes(path: &str) -> String { 60 - if path == "/" { 61 - return "/".to_string(); 62 - } 63 - 64 - if path.ends_with('/') { 65 - path.trim_end_matches('/').to_string() 66 - } else { 67 - path.to_string() 68 - } 69 - }