From 461dfe2fbdea2390c63f30b0ba1d72566c3129fa Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Tue, 2 Feb 2021 10:25:29 +0000 Subject: [PATCH] trim path trailing slashes before route match (#99) --- src/server/mod.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/server/mod.rs b/src/server/mod.rs index fcf26f0..e400d90 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -85,7 +85,10 @@ impl App { let logger2 = logger.clone(); let start = Instant::now(); - let res = if let Ok(route_match) = self.router.recognize(req.uri().path()) { + // allows `/path/` to also match `/path` + let normalized_path = req.uri().path().trim_end_matches('/'); + + let res = if let Ok(route_match) = self.router.recognize(normalized_path) { match (req.method(), route_match.handler()) { (&Method::GET, Route::Index) => { self.index(req, route_match.params().clone(), logger).await