mirror of
https://github.com/tokio-rs/axum.git
synced 2025-01-03 17:52:18 +01:00
Add more tests for the Allow
header when returning 405
(#1526)
Refs: #1525, #733
This commit is contained in:
parent
370ad07e75
commit
587435940b
2 changed files with 6 additions and 1 deletions
|
@ -9,7 +9,7 @@ use crate::{
|
||||||
BoxError, Json, Router,
|
BoxError, Json, Router,
|
||||||
};
|
};
|
||||||
use futures_util::stream::StreamExt;
|
use futures_util::stream::StreamExt;
|
||||||
use http::{header::CONTENT_LENGTH, HeaderMap, Request, Response, StatusCode, Uri};
|
use http::{header::ALLOW, header::CONTENT_LENGTH, HeaderMap, Request, Response, StatusCode, Uri};
|
||||||
use hyper::Body;
|
use hyper::Body;
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use std::{
|
use std::{
|
||||||
|
@ -217,12 +217,14 @@ async fn wrong_method_handler() {
|
||||||
|
|
||||||
let res = client.patch("/").send().await;
|
let res = client.patch("/").send().await;
|
||||||
assert_eq!(res.status(), StatusCode::METHOD_NOT_ALLOWED);
|
assert_eq!(res.status(), StatusCode::METHOD_NOT_ALLOWED);
|
||||||
|
assert_eq!(res.headers()[ALLOW], "GET,HEAD,POST");
|
||||||
|
|
||||||
let res = client.patch("/foo").send().await;
|
let res = client.patch("/foo").send().await;
|
||||||
assert_eq!(res.status(), StatusCode::OK);
|
assert_eq!(res.status(), StatusCode::OK);
|
||||||
|
|
||||||
let res = client.post("/foo").send().await;
|
let res = client.post("/foo").send().await;
|
||||||
assert_eq!(res.status(), StatusCode::METHOD_NOT_ALLOWED);
|
assert_eq!(res.status(), StatusCode::METHOD_NOT_ALLOWED);
|
||||||
|
assert_eq!(res.headers()[ALLOW], "PATCH");
|
||||||
|
|
||||||
let res = client.get("/bar").send().await;
|
let res = client.get("/bar").send().await;
|
||||||
assert_eq!(res.status(), StatusCode::NOT_FOUND);
|
assert_eq!(res.status(), StatusCode::NOT_FOUND);
|
||||||
|
@ -255,12 +257,14 @@ async fn wrong_method_service() {
|
||||||
|
|
||||||
let res = client.patch("/").send().await;
|
let res = client.patch("/").send().await;
|
||||||
assert_eq!(res.status(), StatusCode::METHOD_NOT_ALLOWED);
|
assert_eq!(res.status(), StatusCode::METHOD_NOT_ALLOWED);
|
||||||
|
assert_eq!(res.headers()[ALLOW], "GET,HEAD,POST");
|
||||||
|
|
||||||
let res = client.patch("/foo").send().await;
|
let res = client.patch("/foo").send().await;
|
||||||
assert_eq!(res.status(), StatusCode::OK);
|
assert_eq!(res.status(), StatusCode::OK);
|
||||||
|
|
||||||
let res = client.post("/foo").send().await;
|
let res = client.post("/foo").send().await;
|
||||||
assert_eq!(res.status(), StatusCode::METHOD_NOT_ALLOWED);
|
assert_eq!(res.status(), StatusCode::METHOD_NOT_ALLOWED);
|
||||||
|
assert_eq!(res.headers()[ALLOW], "PATCH");
|
||||||
|
|
||||||
let res = client.get("/bar").send().await;
|
let res = client.get("/bar").send().await;
|
||||||
assert_eq!(res.status(), StatusCode::NOT_FOUND);
|
assert_eq!(res.status(), StatusCode::NOT_FOUND);
|
||||||
|
|
|
@ -70,6 +70,7 @@ async fn wrong_method_nest() {
|
||||||
|
|
||||||
let res = client.post("/").send().await;
|
let res = client.post("/").send().await;
|
||||||
assert_eq!(res.status(), StatusCode::METHOD_NOT_ALLOWED);
|
assert_eq!(res.status(), StatusCode::METHOD_NOT_ALLOWED);
|
||||||
|
assert_eq!(res.headers()[ALLOW], "GET,HEAD");
|
||||||
|
|
||||||
let res = client.patch("/foo").send().await;
|
let res = client.patch("/foo").send().await;
|
||||||
assert_eq!(res.status(), StatusCode::NOT_FOUND);
|
assert_eq!(res.status(), StatusCode::NOT_FOUND);
|
||||||
|
|
Loading…
Reference in a new issue