trim path trailing slashes before route match (#99)

This commit is contained in:
Rob Ede 2021-02-02 10:25:29 +00:00 committed by GitHub
parent 7ebffe019f
commit 461dfe2fbd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -85,7 +85,10 @@ impl App {
let logger2 = logger.clone(); let logger2 = logger.clone();
let start = Instant::now(); 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()) { match (req.method(), route_match.handler()) {
(&Method::GET, Route::Index) => { (&Method::GET, Route::Index) => {
self.index(req, route_match.params().clone(), logger).await self.index(req, route_match.params().clone(), logger).await