diff --git a/core/lib/src/router/router.rs b/core/lib/src/router/router.rs index 37b7cb6584..48d61b85dd 100644 --- a/core/lib/src/router/router.rs +++ b/core/lib/src/router/router.rs @@ -6,6 +6,8 @@ use crate::http::{Method, Status}; use crate::{Route, Catcher}; use crate::router::Collide; +use super::matcher::{paths_match, queries_match}; + #[derive(Debug, Default)] pub(crate) struct Router { routes: HashMap>, @@ -62,7 +64,7 @@ impl Router { self.routes.get(&req.method()) .into_iter() .flatten() - .any(|route| super::matcher::paths_match(route, req) && super::matcher::queries_match(route, req)) + .any(|route| paths_match(route, req) && queries_match(route, req)) } const ALL_METHODS: &[Method] = &[ @@ -79,7 +81,7 @@ impl Router { .filter(|method| *method != &req.method()) .filter_map(|method| self.routes.get(method)) .flatten() - .any(|route| super::matcher::paths_match(route, req)) + .any(|route| paths_match(route, req)) } // For many catchers, using aho-corasick or similar should be much faster. diff --git a/core/lib/src/server.rs b/core/lib/src/server.rs index 48a86ac4fc..b37b3247d0 100644 --- a/core/lib/src/server.rs +++ b/core/lib/src/server.rs @@ -343,12 +343,16 @@ impl Rocket { error_!("No matching routes for {}.", request); if request.route().is_none() { - // We failed to find a route which matches on path, query AND formats + // We failed to find a route which matches on path, query AND formats. if self.router.matches_except_formats(request) { // Tailor the error code to the interpretation of the request in question. - status = if request.method().supports_payload() { Status::UnsupportedMediaType } else { Status::NotAcceptable }; + if request.method().supports_payload() { + status = Status::UnsupportedMediaType; + } else { + status = Status::NotAcceptable; + } } else if self.router.matches_except_method(request) { - // Found a more suitable error code from simple route paths implemented on different methods + // Found a more suitable error code for paths implemented on different methods. status = Status::MethodNotAllowed; } }