Skip to content

Commit 1e2567c

Browse files
authored
Fix missing Allow when middleware are applied to MethodRouter (#1773)
1 parent eb5db64 commit 1e2567c

File tree

4 files changed

+16
-18
lines changed

4 files changed

+16
-18
lines changed

axum/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
# Unreleased
99

10-
- None.
10+
- **fixed:** Fix `Allow` missing from routers with middleware
1111

1212
# 0.6.7 (17. February, 2023)
1313

axum/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ axum-core = { path = "../axum-core", version = "0.3.2" }
3535
bitflags = "1.0"
3636
bytes = "1.0"
3737
futures-util = { version = "0.3", default-features = false, features = ["alloc"] }
38-
http = "0.2.5"
38+
http = "0.2.9"
3939
http-body = "0.4.4"
40-
hyper = { version = "0.14.14", features = ["stream"] }
41-
itoa = "1.0.1"
40+
hyper = { version = "0.14.24", features = ["stream"] }
41+
itoa = "=1.0.5"
4242
matchit = "0.7"
4343
memchr = "2.4.1"
4444
mime = "0.3.16"
@@ -72,7 +72,7 @@ axum-macros = { path = "../axum-macros", version = "0.3.4", features = ["__priva
7272
futures = "0.3"
7373
quickcheck = "1.0"
7474
quickcheck_macros = "1.0"
75-
reqwest = { version = "0.11.11", default-features = false, features = ["json", "stream", "multipart"] }
75+
reqwest = { version = "0.11.14", default-features = false, features = ["json", "stream", "multipart"] }
7676
serde = { version = "1.0", features = ["derive"] }
7777
serde_json = "1.0"
7878
time = { version = "0.3", features = ["serde-human-readable"] }

axum/src/routing/method_routing.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,6 +1487,17 @@ mod tests {
14871487
assert_eq!(headers[ALLOW], "GET,POST");
14881488
}
14891489

1490+
#[crate::test]
1491+
async fn allow_header_noop_middleware() {
1492+
let mut svc = MethodRouter::new()
1493+
.get(ok)
1494+
.layer(tower::layer::util::Identity::new());
1495+
1496+
let (status, headers, _) = call(Method::DELETE, &mut svc).await;
1497+
assert_eq!(status, StatusCode::METHOD_NOT_ALLOWED);
1498+
assert_eq!(headers[ALLOW], "GET,HEAD");
1499+
}
1500+
14901501
#[crate::test]
14911502
#[should_panic(
14921503
expected = "Overlapping method route. Cannot add two method routes that both handle `GET`"

axum/src/routing/route.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,6 @@ where
155155

156156
#[inline]
157157
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
158-
#[derive(Clone, Copy)]
159-
struct AlreadyPassedThroughRouteFuture;
160-
161158
let this = self.project();
162159

163160
let mut res = match this.kind.project() {
@@ -171,16 +168,6 @@ where
171168
}
172169
};
173170

174-
if res
175-
.extensions()
176-
.get::<AlreadyPassedThroughRouteFuture>()
177-
.is_some()
178-
{
179-
return Poll::Ready(Ok(res));
180-
} else {
181-
res.extensions_mut().insert(AlreadyPassedThroughRouteFuture);
182-
}
183-
184171
set_allow_header(res.headers_mut(), this.allow_header);
185172

186173
// make sure to set content-length before removing the body

0 commit comments

Comments
 (0)