1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-05-20 09:18:26 +00:00
This commit is contained in:
Sabin 2024-05-07 20:58:04 -07:00 committed by GitHub
commit b1666b61d0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 40 additions and 12 deletions

View file

@ -28,5 +28,5 @@ actix-utils = "3"
actix-web = "4"
futures-core = { version = "0.3.17", default-features = false, features = ["alloc"] }
trybuild = "1"
trybuild = "1.0"
rustversion = "1"

View file

@ -84,7 +84,7 @@ use quote::quote;
mod route;
/// Creates resource handler, allowing multiple HTTP method guards.
/// Creates resource handler , allowing multiple HTTP method guards.
///
/// # Syntax
/// ```plain
@ -196,6 +196,7 @@ method_macro!(Connect, connect);
method_macro!(Options, options);
method_macro!(Trace, trace);
method_macro!(Patch, patch);
method_macro!(All, all);
/// Marks async main function as the Actix Web system entry-point.
///

View file

@ -62,12 +62,13 @@ macro_rules! standard_method_type {
$(
$variant,
)+
All
}
impl MethodType {
fn as_str(&self) -> &'static str {
match self {
$(Self::$variant => stringify!($variant),)+
$(Self::$variant => stringify!($variant), &MethodType::All => stringify!("All"),)+
}
}

View file

@ -1,4 +1,4 @@
#[rustversion::stable(1.72)] // MSRV
//#[rustversion::stable(1.72)] // MSRV
#[test]
fn compile_macros() {
let t = trybuild::TestCases::new();
@ -21,4 +21,5 @@ fn compile_macros() {
t.pass("tests/trybuild/docstring-ok.rs");
t.pass("tests/trybuild/test-runtime.rs");
}
t.pass("tests/trybuild/route-any-method.rs");
}

View file

@ -0,0 +1,25 @@
use std::str::FromStr;
use actix_web::http::Method;
use actix_web_codegen::route;
#[route("/single", method = "ALL")]
async fn index() -> String {
"Hello Single!".to_owned()
}
#[route("/multi", method = "GET", method = "ALL")]
async fn custom() -> String {
"Hello Multi!".to_owned()
}
#[actix_web::main]
async fn main() {
use actix_web::App;
let srv = actix_test::start(|| App::new().service(index).service(custom));
let request = srv.request(Method::from_str("ALL").unwrap(), srv.url("/single"));
let response = request.send().await.unwrap();
assert!(response.status().is_success());
}

View file

@ -8,7 +8,7 @@ async fn index() -> String {
"Hello Single!".to_owned()
}
#[route("/multi", method = "GET", method = "CUSTOM")]
#[route("/multi", method = "CUSTOM")]
async fn custom() -> String {
"Hello Multi!".to_owned()
}
@ -19,17 +19,17 @@ async fn main() {
let srv = actix_test::start(|| App::new().service(index).service(custom));
let request = srv.request(Method::GET, srv.url("/"));
let response = request.send().await.unwrap();
assert!(response.status().is_client_error());
// let request = srv.request(Method::GET, srv.url("/"));
// let response = request.send().await.unwrap();
// assert!(response.status().is_client_error());
let request = srv.request(Method::from_str("CUSTOM").unwrap(), srv.url("/single"));
let response = request.send().await.unwrap();
assert!(response.status().is_success());
let request = srv.request(Method::GET, srv.url("/multi"));
let response = request.send().await.unwrap();
assert!(response.status().is_success());
// let request = srv.request(Method::GET, srv.url("/multi"));
// let response = request.send().await.unwrap();
// assert!(response.status().is_success());
let request = srv.request(Method::from_str("CUSTOM").unwrap(), srv.url("/multi"));
let response = request.send().await.unwrap();