mirror of
https://github.com/tokio-rs/axum.git
synced 2025-03-26 00:27:01 +01:00
Fix missing Allow
when middleware are applied to MethodRouter
(#1773)
This commit is contained in:
parent
eb5db64a6f
commit
1e2567c39f
4 changed files with 16 additions and 18 deletions
axum
|
@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
# Unreleased
|
||||
|
||||
- None.
|
||||
- **fixed:** Fix `Allow` missing from routers with middleware
|
||||
|
||||
# 0.6.7 (17. February, 2023)
|
||||
|
||||
|
|
|
@ -35,10 +35,10 @@ axum-core = { path = "../axum-core", version = "0.3.2" }
|
|||
bitflags = "1.0"
|
||||
bytes = "1.0"
|
||||
futures-util = { version = "0.3", default-features = false, features = ["alloc"] }
|
||||
http = "0.2.5"
|
||||
http = "0.2.9"
|
||||
http-body = "0.4.4"
|
||||
hyper = { version = "0.14.14", features = ["stream"] }
|
||||
itoa = "1.0.1"
|
||||
hyper = { version = "0.14.24", features = ["stream"] }
|
||||
itoa = "=1.0.5"
|
||||
matchit = "0.7"
|
||||
memchr = "2.4.1"
|
||||
mime = "0.3.16"
|
||||
|
@ -72,7 +72,7 @@ axum-macros = { path = "../axum-macros", version = "0.3.4", features = ["__priva
|
|||
futures = "0.3"
|
||||
quickcheck = "1.0"
|
||||
quickcheck_macros = "1.0"
|
||||
reqwest = { version = "0.11.11", default-features = false, features = ["json", "stream", "multipart"] }
|
||||
reqwest = { version = "0.11.14", default-features = false, features = ["json", "stream", "multipart"] }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
time = { version = "0.3", features = ["serde-human-readable"] }
|
||||
|
|
|
@ -1487,6 +1487,17 @@ mod tests {
|
|||
assert_eq!(headers[ALLOW], "GET,POST");
|
||||
}
|
||||
|
||||
#[crate::test]
|
||||
async fn allow_header_noop_middleware() {
|
||||
let mut svc = MethodRouter::new()
|
||||
.get(ok)
|
||||
.layer(tower::layer::util::Identity::new());
|
||||
|
||||
let (status, headers, _) = call(Method::DELETE, &mut svc).await;
|
||||
assert_eq!(status, StatusCode::METHOD_NOT_ALLOWED);
|
||||
assert_eq!(headers[ALLOW], "GET,HEAD");
|
||||
}
|
||||
|
||||
#[crate::test]
|
||||
#[should_panic(
|
||||
expected = "Overlapping method route. Cannot add two method routes that both handle `GET`"
|
||||
|
|
|
@ -155,9 +155,6 @@ where
|
|||
|
||||
#[inline]
|
||||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
#[derive(Clone, Copy)]
|
||||
struct AlreadyPassedThroughRouteFuture;
|
||||
|
||||
let this = self.project();
|
||||
|
||||
let mut res = match this.kind.project() {
|
||||
|
@ -171,16 +168,6 @@ where
|
|||
}
|
||||
};
|
||||
|
||||
if res
|
||||
.extensions()
|
||||
.get::<AlreadyPassedThroughRouteFuture>()
|
||||
.is_some()
|
||||
{
|
||||
return Poll::Ready(Ok(res));
|
||||
} else {
|
||||
res.extensions_mut().insert(AlreadyPassedThroughRouteFuture);
|
||||
}
|
||||
|
||||
set_allow_header(res.headers_mut(), this.allow_header);
|
||||
|
||||
// make sure to set content-length before removing the body
|
||||
|
|
Loading…
Add table
Reference in a new issue