diff --git a/CHANGELOG.md b/CHANGELOG.md index ea357280..0d4df94e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 # Unreleased -- None. +- Clarify that `handler::any` and `service::any` only accepts standard HTTP + methods ([#337]) + +[#337]: https://github.com/tokio-rs/axum/pull/337 # 0.2.5 (18. September, 2021) diff --git a/src/handler/mod.rs b/src/handler/mod.rs index 9542b076..6365c1fd 100644 --- a/src/handler/mod.rs +++ b/src/handler/mod.rs @@ -28,8 +28,7 @@ mod into_service; pub use self::into_service::IntoService; -/// Route requests to the given handler regardless of the HTTP method of the -/// request. +/// Route requests with any standard HTTP method to the given handler. /// /// # Example /// @@ -41,12 +40,28 @@ pub use self::into_service::IntoService; /// /// async fn handler() {} /// -/// // All requests to `/` will go to `handler` regardless of the HTTP method. /// let app = Router::new().route("/", any(handler)); /// # async { /// # axum::Server::bind(&"".parse().unwrap()).serve(app.into_make_service()).await.unwrap(); /// # }; /// ``` +/// +/// Note that this only accepts the standard HTTP methods. If you need to +/// support non-standard methods use [`Handler::into_service`]: +/// +/// ```rust +/// use axum::{ +/// handler::Handler, +/// Router, +/// }; +/// +/// async fn handler() {} +/// +/// let app = Router::new().route("/", handler.into_service()); +/// # async { +/// # axum::Server::bind(&"".parse().unwrap()).serve(app.into_make_service()).await.unwrap(); +/// # }; +/// ``` pub fn any(handler: H) -> OnMethod where H: Handler, diff --git a/src/routing/method_filter.rs b/src/routing/method_filter.rs index 0381f74b..d5da2cb5 100644 --- a/src/routing/method_filter.rs +++ b/src/routing/method_filter.rs @@ -16,7 +16,7 @@ bitflags! { const OPTIONS = 0b000010000; /// Match `PATCH` requests. const PATCH = 0b000100000; - /// Match `POSt` requests. + /// Match `POST` requests. const POST = 0b001000000; /// Match `PUT` requests. const PUT = 0b010000000; diff --git a/src/service/mod.rs b/src/service/mod.rs index 5138abac..1d53837a 100644 --- a/src/service/mod.rs +++ b/src/service/mod.rs @@ -114,9 +114,12 @@ use tower_service::Service; pub mod future; -/// Route requests to the given service regardless of the HTTP method. +/// Route requests with any standard HTTP method to the given service. /// /// See [`get`] for an example. +/// +/// Note that this only accepts the standard HTTP methods. If you need to +/// support non-standard methods you can route directly to a [`Service`]. pub fn any(svc: S) -> OnMethod, B> where S: Service> + Clone,