Handle METHOD_NOT_ALLOWED in 404 example (#131)

If a route existed but had no handler for the method, the code used in
the 404 example wouldn't catch it.
This commit is contained in:
David Pedersen 2021-08-06 01:15:23 +02:00 committed by GitHub
parent d4ce90e2e6
commit 2be79168d8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -39,12 +39,14 @@ async fn handler() -> response::Html<&'static str> {
} }
fn map_404(response: Response<BoxBody>) -> Response<BoxBody> { fn map_404(response: Response<BoxBody>) -> Response<BoxBody> {
if response.status() != StatusCode::NOT_FOUND { if response.status() == StatusCode::NOT_FOUND
return response; || response.status() == StatusCode::METHOD_NOT_ALLOWED
{
return Response::builder()
.status(StatusCode::NOT_FOUND)
.body(box_body(Body::from("nothing to see here")))
.unwrap();
} }
Response::builder() response
.status(StatusCode::NOT_FOUND)
.body(box_body(Body::from("nothing to see here")))
.unwrap()
} }