Skip to content

Commit

Permalink
Fix missing Allow when middleware are applied to MethodRouter (#1773
Browse files Browse the repository at this point in the history
)
  • Loading branch information
davidpdrsn committed Feb 20, 2023
1 parent eb5db64 commit 1e2567c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 18 deletions.
2 changes: 1 addition & 1 deletion axum/CHANGELOG.md
Expand Up @@ -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)

Expand Down
8 changes: 4 additions & 4 deletions axum/Cargo.toml
Expand Up @@ -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"
Expand Down Expand Up @@ -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"] }
Expand Down
11 changes: 11 additions & 0 deletions axum/src/routing/method_routing.rs
Expand Up @@ -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`"
Expand Down
13 changes: 0 additions & 13 deletions axum/src/routing/route.rs
Expand Up @@ -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() {
Expand All @@ -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
Expand Down

0 comments on commit 1e2567c

Please sign in to comment.