Filter the method, fix typo, add comment
@@ -61,9 +61,16 @@ impl<State: 'static> Router<State> {
// 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.values().any(|r| r.recognize(path).is_ok()) {
+ } 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_allawed,
+ endpoint: &method_not_allowed,
params: Params::new(),
}
} else {
@@ -79,6 +86,6 @@ fn not_found_endpoint<State>(_cx: Request<State>) -> BoxFuture<'static, Response
Box::pin(async move { Response::new(http::StatusCode::NOT_FOUND.as_u16()) })
}
-fn method_not_allawed<State>(_cx: Request<State>) -> BoxFuture<'static, Response> {
+fn method_not_allowed<State>(_cx: Request<State>) -> BoxFuture<'static, Response> {
Box::pin(async move { Response::new(http::StatusCode::METHOD_NOT_ALLOWED.as_u16()) })
}
