diff --git a/actix-web-codegen/CHANGES.md b/actix-web-codegen/CHANGES.md index cb37bfdb0..40ee414f3 100644 --- a/actix-web-codegen/CHANGES.md +++ b/actix-web-codegen/CHANGES.md @@ -1,6 +1,7 @@ # Changes ## Unreleased - 2022-xx-xx +- Add support for Custom Methods with `#[route]` macro. [#2969] ## 4.1.0 - 2022-09-11 diff --git a/actix-web-codegen/src/lib.rs b/actix-web-codegen/src/lib.rs index 4b6dc43c5..5d392be1d 100644 --- a/actix-web-codegen/src/lib.rs +++ b/actix-web-codegen/src/lib.rs @@ -105,7 +105,7 @@ mod route; /// ``` /// # use actix_web::HttpResponse; /// # use actix_web_codegen::route; -/// #[route("/test", method = "GET", method = "HEAD")] +/// #[route("/test", method = "GET", method = "HEAD", method = "CUSTOM")] /// async fn example() -> HttpResponse { /// HttpResponse::Ok().finish() /// } diff --git a/actix-web-codegen/tests/test_macro.rs b/actix-web-codegen/tests/test_macro.rs index 10e906967..e61a7d6bc 100644 --- a/actix-web-codegen/tests/test_macro.rs +++ b/actix-web-codegen/tests/test_macro.rs @@ -86,7 +86,13 @@ async fn get_param_test(_: web::Path) -> impl Responder { HttpResponse::Ok() } -#[route("/multi", method = "GET", method = "POST", method = "HEAD")] +#[route( + "/multi", + method = "GET", + method = "POST", + method = "HEAD", + method = "CREATE" +)] async fn route_test() -> impl Responder { HttpResponse::Ok() } diff --git a/actix-web/CHANGES.md b/actix-web/CHANGES.md index 6fc3c93d7..f9a4c2240 100644 --- a/actix-web/CHANGES.md +++ b/actix-web/CHANGES.md @@ -8,6 +8,7 @@ - Add rudimentary redirection service at `web::redirect()` / `web::Redirect`. [#1961] - Add `guard::Acceptable` for matching against `Accept` header mime types. [#2265] - Add fallible versions of test helpers: `try_call_service`, `try_call_and_read_body_json`, `try_read_body`, and `try_read_body_json`. [#2961] +- Add `guard::Custom()` for handling `#[route]` macro with custom Methods. . [#2969] ### Fixed - Add `Allow` header to `Resource`'s default responses when no routes are matched. [#2949] diff --git a/actix-web/src/guard/mod.rs b/actix-web/src/guard/mod.rs index 70e296c99..9bb2ca5e3 100644 --- a/actix-web/src/guard/mod.rs +++ b/actix-web/src/guard/mod.rs @@ -339,6 +339,16 @@ method_guard!(Connect, CONNECT); method_guard!(Patch, PATCH); method_guard!(Trace, TRACE); +/// +/// # Examples +#[doc = "The route in this example will respond to all uppercase ASCII requests."] +/// ``` +/// use actix_web::{guard, web, HttpResponse}; +/// +/// web::route() +#[doc = " .guard(guard::Custom(\"HELLO\"))"] +/// .to(|| HttpResponse::Ok()); +/// ``` #[allow(non_snake_case)] pub fn Custom(custom_method: &str) -> impl Guard { MethodGuard(HttpMethod::from_bytes(custom_method.as_bytes()).unwrap())