Returning 405 (Method not allowed) when using route macros
- Lingua principale
- Rust
- Stelle
- 24.8k
- Fork
- 1.9k
- Merge medio
- 23h 10m
- PR unite (30g)
- 26
Descrizione
## Expected Behavior
When a route string can be matched by one (or more) route macro paths (but zero method matches) then a 405 should be returned.
## Current Behavior
A 404 is returned.
## Steps to Reproduce (for bugs)
```rust
use actix_web::{get, App, Responder};
fn main() {}
#[get("/hello")]
async fn get_hello() -> impl Responder {
format!("Hello world!")
}
#[cfg(test)]
mod tests {
use super::*;
use actix_web::{http, test};
#[actix_web::test]
async fn test() {
let app = test::init_service(App::new().service(get_hello)).await;
let req = test::TestRequest::get().uri("/hello").to_request();
let resp = test::call_service(&app, req).await;
assert_eq!(resp.status(), http::StatusCode::OK);
let req = test::TestRequest::post().uri("/hello").to_request();
let resp = test::call_service(&app, req).await;
// Assertion fails!
assert_eq!(resp.status(), http::StatusCode::METHOD_NOT_ALLOWED);
}
}
```
## Your Environment
- Rust Version: 1.59
- Actix Web Version: 4.0.1
Guida per i contributori
Apri la guida per i contributori
Valutazione
Questa issue non è ancora stata valutata.