🏗️ 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.

feat(router): Add missing trailing slash corrector

Fuwn 22299ccd 1776a876

+28 -9
+4 -1
examples/fix_path.rs
··· 22 22 windmark::router::Router::new() 23 23 .set_private_key_file("windmark_private.pem") 24 24 .set_certificate_file("windmark_public.pem") 25 - .add_options(&[windmark::router_option::RouterOption::TrimTrailingSlashes]) 25 + .add_options(&[ 26 + windmark::router_option::RouterOption::TrimTrailingSlashes, 27 + windmark::router_option::RouterOption::AddMissingTrailingSlash, 28 + ]) 26 29 .mount( 27 30 "/close", 28 31 windmark::success!("Visit '/close/'; you should be close enough!"),
+19 -7
src/router.rs
··· 423 423 let mut path = url.path().to_string(); 424 424 let mut route = self.routes.at(&path); 425 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); 426 + if route.is_err() { 427 + if 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 + } else if self 434 + .options 435 + .contains(&RouterOption::AddMissingTrailingSlash) 436 + && !path.ends_with('/') 437 + { 438 + let path_with_slash = format!("{path}/"); 439 + 440 + if self.routes.at(&path_with_slash).is_ok() { 441 + path = path_with_slash; 442 + route = self.routes.at(&path); 443 + } 444 + } 433 445 } 434 446 435 447 let peer_certificate = stream.ssl().peer_certificate();
+5 -1
src/router_option.rs
··· 1 1 /// Options that can be set for the `Router` 2 2 #[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)] 3 3 pub enum RouterOption { 4 - /// Trim trailing slashes from the URL path 4 + /// Trim trailing slashes from the URL path if it is present and a route 5 + /// match exists 5 6 TrimTrailingSlashes, 7 + /// Add a trailing slash to the URL path if it is missing and a route 8 + /// match exists 9 + AddMissingTrailingSlash, 6 10 }