diff --git a/src/router.rs b/src/router.rs index f5af72d8b..7c52a7fef 100644 --- a/src/router.rs +++ b/src/router.rs @@ -61,6 +61,18 @@ impl Router { // if not then fallback to the behavior of HTTP GET else proceed as usual self.route(path, http::Method::GET) + } else if self + .method_map + .iter() + .filter(|(k, _)| *k != method) + .any(|(_, r)| r.recognize(path).is_ok()) + { + // If this `path` can be handled by a callback registered with a different HTTP method + // should return 405 Method Not Allowed + Selection { + endpoint: &method_not_allowed, + params: Params::new(), + } } else { Selection { endpoint: ¬_found_endpoint, @@ -73,3 +85,7 @@ impl Router { fn not_found_endpoint(_cx: Request) -> BoxFuture<'static, Response> { Box::pin(async move { Response::new(http::StatusCode::NOT_FOUND.as_u16()) }) } + +fn method_not_allowed(_cx: Request) -> BoxFuture<'static, Response> { + Box::pin(async move { Response::new(http::StatusCode::METHOD_NOT_ALLOWED.as_u16()) }) +}