From 2fe435173e158c58c0075386a69f62b24eec131c Mon Sep 17 00:00:00 2001 From: Sandor Apati Date: Sat, 21 Sep 2024 09:09:23 +0200 Subject: [PATCH 01/16] ECOSYSTEM.md: Add link to rust-api.dev (#2923) --- ECOSYSTEM.md | 1 + 1 file changed, 1 insertion(+) diff --git a/ECOSYSTEM.md b/ECOSYSTEM.md index ff374e86..9a27ab34 100644 --- a/ECOSYSTEM.md +++ b/ECOSYSTEM.md @@ -105,6 +105,7 @@ If your project isn't listed here and you would like it to be, please feel free - [Introduction to axum]: YouTube playlist - [Rust Axum Full Course]: YouTube video - [Deploying Axum projects with Shuttle] +- [API Development with Rust](https://rust-api.dev/docs/front-matter/preface/): REST APIs based on Axum [axum-tutorial]: https://github.com/programatik29/axum-tutorial [axum-tutorial-website]: https://programatik29.github.io/axum-tutorial/ From 068c9a3e96463ef6eb78f68ca7bc1bcc6eb638e7 Mon Sep 17 00:00:00 2001 From: Sabrina Jewson Date: Sun, 22 Sep 2024 12:32:59 +0100 Subject: [PATCH 02/16] Clarify some subtleties of routing (#2896) --- axum/src/docs/routing/fallback.md | 6 +++++- axum/src/docs/routing/nest.md | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/axum/src/docs/routing/fallback.md b/axum/src/docs/routing/fallback.md index 27fb76a5..a864b7a4 100644 --- a/axum/src/docs/routing/fallback.md +++ b/axum/src/docs/routing/fallback.md @@ -23,7 +23,11 @@ async fn fallback(uri: Uri) -> (StatusCode, String) { Fallbacks only apply to routes that aren't matched by anything in the router. If a handler is matched by a request but returns 404 the -fallback is not called. +fallback is not called. Note that this applies to [`MethodRouter`]s too: if the +request hits a valid path but the [`MethodRouter`] does not have an appropriate +method handler installed, the fallback is not called (use +[`MethodRouter::fallback`] for this purpose instead). + # Handling all requests without other routes diff --git a/axum/src/docs/routing/nest.md b/axum/src/docs/routing/nest.md index 3151729e..845072f0 100644 --- a/axum/src/docs/routing/nest.md +++ b/axum/src/docs/routing/nest.md @@ -82,6 +82,11 @@ let app = Router::new() # let _: Router = app; ``` +Additionally, while the wildcard route `/foo/*rest` will not match the +paths `/foo` or `/foo/`, a nested router at `/foo` will match the path `/foo` +(but not `/foo/`), and a nested router at `/foo/` will match the path `/foo/` +(but not `/foo`). + # Fallbacks If a nested router doesn't have its own fallback then it will inherit the From 4179d11797bd8880c74a306b7e05e9d0f081ca1d Mon Sep 17 00:00:00 2001 From: Hytak Date: Tue, 24 Sep 2024 19:17:16 +0200 Subject: [PATCH 03/16] Stricter path deserialization for tuples and tuple structs (#2931) --- axum/CHANGELOG.md | 6 ++++++ axum/src/extract/path/de.rs | 30 ++++++++++++++---------------- axum/src/extract/path/mod.rs | 27 +++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 16 deletions(-) diff --git a/axum/CHANGELOG.md b/axum/CHANGELOG.md index 0379672c..54792597 100644 --- a/axum/CHANGELOG.md +++ b/axum/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +# Unreleased + +- **breaking:** The tuple and tuple_struct `Path` extractor deserializers now check that the number of parameters matches the tuple length exactly ([#2931]) + +[#2931]: https://github.com/tokio-rs/axum/pull/2931 + # 0.7.6 - **change:** Avoid cloning `Arc` during deserialization of `Path` diff --git a/axum/src/extract/path/de.rs b/axum/src/extract/path/de.rs index 8ba8a431..2d0b04f5 100644 --- a/axum/src/extract/path/de.rs +++ b/axum/src/extract/path/de.rs @@ -140,7 +140,7 @@ impl<'de> Deserializer<'de> for PathDeserializer<'de> { where V: Visitor<'de>, { - if self.url_params.len() < len { + if self.url_params.len() != len { return Err(PathDeserializationError::wrong_number_of_parameters() .got(self.url_params.len()) .expected(len)); @@ -160,7 +160,7 @@ impl<'de> Deserializer<'de> for PathDeserializer<'de> { where V: Visitor<'de>, { - if self.url_params.len() < len { + if self.url_params.len() != len { return Err(PathDeserializationError::wrong_number_of_parameters() .got(self.url_params.len()) .expected(len)); @@ -773,20 +773,6 @@ mod tests { ); } - #[test] - fn test_parse_tuple_ignoring_additional_fields() { - let url_params = create_url_params(vec![ - ("a", "abc"), - ("b", "true"), - ("c", "1"), - ("d", "false"), - ]); - assert_eq!( - <(&str, bool, u32)>::deserialize(PathDeserializer::new(&url_params)).unwrap(), - ("abc", true, 1) - ); - } - #[test] fn test_parse_map() { let url_params = create_url_params(vec![("a", "1"), ("b", "true"), ("c", "abc")]); @@ -813,6 +799,18 @@ mod tests { }; } + #[test] + fn test_parse_tuple_too_many_fields() { + test_parse_error!( + vec![("a", "abc"), ("b", "true"), ("c", "1"), ("d", "false"),], + (&str, bool, u32), + ErrorKind::WrongNumberOfParameters { + got: 4, + expected: 3, + } + ); + } + #[test] fn test_wrong_number_of_parameters_error() { test_parse_error!( diff --git a/axum/src/extract/path/mod.rs b/axum/src/extract/path/mod.rs index 330e270e..fda8364c 100644 --- a/axum/src/extract/path/mod.rs +++ b/axum/src/extract/path/mod.rs @@ -747,6 +747,33 @@ mod tests { ); } + #[crate::test] + async fn tuple_param_matches_exactly() { + #[allow(dead_code)] + #[derive(Deserialize)] + struct Tuple(String, String); + + let app = Router::new() + .route("/foo/:a/:b/:c", get(|_: Path<(String, String)>| async {})) + .route("/bar/:a/:b/:c", get(|_: Path| async {})); + + let client = TestClient::new(app); + + let res = client.get("/foo/a/b/c").await; + assert_eq!(res.status(), StatusCode::INTERNAL_SERVER_ERROR); + assert_eq!( + res.text().await, + "Wrong number of path arguments for `Path`. Expected 2 but got 3", + ); + + let res = client.get("/bar/a/b/c").await; + assert_eq!(res.status(), StatusCode::INTERNAL_SERVER_ERROR); + assert_eq!( + res.text().await, + "Wrong number of path arguments for `Path`. Expected 2 but got 3", + ); + } + #[crate::test] async fn deserialize_into_vec_of_tuples() { let app = Router::new().route( From ef50e5c18012b1788d798eede7776157fe59ca1b Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Tue, 24 Sep 2024 21:50:53 +0000 Subject: [PATCH 04/16] Upgrade private dependencies (#2935) --- axum/Cargo.toml | 6 +++--- examples/http-proxy/Cargo.toml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/axum/Cargo.toml b/axum/Cargo.toml index 4ef57819..b4cd4363 100644 --- a/axum/Cargo.toml +++ b/axum/Cargo.toml @@ -63,7 +63,7 @@ tower-service = "0.3" # optional dependencies axum-macros = { path = "../axum-macros", version = "0.4.2", optional = true } -base64 = { version = "0.21.0", optional = true } +base64 = { version = "0.22.1", optional = true } hyper = { version = "1.1.0", optional = true } hyper-util = { version = "0.1.3", features = ["tokio", "server", "service"], optional = true } multer = { version = "3.0.0", optional = true } @@ -72,7 +72,7 @@ serde_path_to_error = { version = "0.1.8", optional = true } serde_urlencoded = { version = "0.7", optional = true } sha1 = { version = "0.10", optional = true } tokio = { package = "tokio", version = "1.25.0", features = ["time"], optional = true } -tokio-tungstenite = { version = "0.23", optional = true } +tokio-tungstenite = { version = "0.24.0", optional = true } tracing = { version = "0.1", default-features = false, optional = true } [dependencies.tower-http] @@ -121,7 +121,7 @@ serde_json = "1.0" time = { version = "0.3", features = ["serde-human-readable"] } tokio = { package = "tokio", version = "1.25.0", features = ["macros", "rt", "rt-multi-thread", "net", "test-util"] } tokio-stream = "0.1" -tokio-tungstenite = "0.23" +tokio-tungstenite = "0.24.0" tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["json"] } uuid = { version = "1.0", features = ["serde", "v4"] } diff --git a/examples/http-proxy/Cargo.toml b/examples/http-proxy/Cargo.toml index aa607002..63854471 100644 --- a/examples/http-proxy/Cargo.toml +++ b/examples/http-proxy/Cargo.toml @@ -9,6 +9,6 @@ axum = { path = "../../axum" } hyper = { version = "1", features = ["full"] } hyper-util = "0.1.1" tokio = { version = "1.0", features = ["full"] } -tower = { version = "0.4", features = ["make"] } +tower = { version = "0.4", features = ["make", "util"] } tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter"] } From 391f2deccd6a77139bd6dcaa8579cdbce9d2184a Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Wed, 25 Sep 2024 07:44:35 +0000 Subject: [PATCH 05/16] core: Fix compile errors from __log_rejection (#2933) --- axum-core/src/lib.rs | 5 +++++ axum-core/src/macros.rs | 6 +++--- axum-extra/Cargo.toml | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/axum-core/src/lib.rs b/axum-core/src/lib.rs index cd1dc2ee..134c566b 100644 --- a/axum-core/src/lib.rs +++ b/axum-core/src/lib.rs @@ -50,6 +50,11 @@ #[macro_use] pub(crate) mod macros; +#[doc(hidden)] // macro helpers +pub mod __private { + #[cfg(feature = "tracing")] + pub use tracing; +} mod error; mod ext_traits; diff --git a/axum-core/src/macros.rs b/axum-core/src/macros.rs index 7d723818..aa99ba40 100644 --- a/axum-core/src/macros.rs +++ b/axum-core/src/macros.rs @@ -9,12 +9,12 @@ macro_rules! __log_rejection { status = $status:expr, ) => { { - tracing::event!( + $crate::__private::tracing::event!( target: "axum::rejection", - tracing::Level::TRACE, + $crate::__private::tracing::Level::TRACE, status = $status.as_u16(), body = $body_text, - rejection_type = std::any::type_name::<$ty>(), + rejection_type = ::std::any::type_name::<$ty>(), "rejecting request", ); } diff --git a/axum-extra/Cargo.toml b/axum-extra/Cargo.toml index bf0ba2a4..eea44bdd 100644 --- a/axum-extra/Cargo.toml +++ b/axum-extra/Cargo.toml @@ -34,7 +34,7 @@ json-lines = [ multipart = ["dep:multer"] protobuf = ["dep:prost"] query = ["dep:serde_html_form"] -tracing = ["dep:tracing", "axum-core/tracing", "axum/tracing"] +tracing = ["axum-core/tracing", "axum/tracing"] typed-header = ["dep:headers"] typed-routing = ["dep:axum-macros", "dep:percent-encoding", "dep:serde_html_form", "dep:form_urlencoded"] From 2fb6cea732461c8f25b025fa37ac8d3375235a7b Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Wed, 25 Sep 2024 07:44:47 +0000 Subject: [PATCH 06/16] Remove unused dependencies from examples (#2934) --- axum-core/Cargo.toml | 3 +++ examples/chat/Cargo.toml | 1 - examples/compression/Cargo.toml | 1 - .../Cargo.toml | 3 --- examples/customize-path-rejection/Cargo.toml | 1 - examples/diesel-async-postgres/Cargo.toml | 1 - examples/diesel-postgres/Cargo.toml | 1 - examples/global-404-handler/Cargo.toml | 1 - examples/graceful-shutdown/Cargo.toml | 4 ---- examples/key-value-store/Cargo.toml | 1 - examples/low-level-rustls/Cargo.toml | 1 - examples/print-request-response/Cargo.toml | 2 -- examples/query-params-with-empty-strings/Cargo.toml | 1 - examples/readme/Cargo.toml | 1 - examples/rest-grpc-multiplex/Cargo.toml | 12 ++++++------ examples/simple-router-wasm/Cargo.toml | 3 +++ examples/static-file-server/Cargo.toml | 1 - examples/testing-websockets/Cargo.toml | 1 - examples/testing/Cargo.toml | 1 - examples/tls-graceful-shutdown/Cargo.toml | 1 - examples/unix-domain-socket/Cargo.toml | 1 - examples/validator/Cargo.toml | 1 - examples/websockets/Cargo.toml | 1 - 23 files changed, 12 insertions(+), 32 deletions(-) diff --git a/axum-core/Cargo.toml b/axum-core/Cargo.toml index 2d4d0759..afb2fbf0 100644 --- a/axum-core/Cargo.toml +++ b/axum-core/Cargo.toml @@ -55,6 +55,9 @@ allowed = [ "http_body", ] +[package.metadata.cargo-machete] +ignored = ["tower-http"] # See __private_docs feature + [package.metadata.docs.rs] all-features = true rustdoc-args = ["--cfg", "docsrs"] diff --git a/examples/chat/Cargo.toml b/examples/chat/Cargo.toml index 90d88246..2beb99cf 100644 --- a/examples/chat/Cargo.toml +++ b/examples/chat/Cargo.toml @@ -8,6 +8,5 @@ publish = false axum = { path = "../../axum", features = ["ws"] } futures = "0.3" tokio = { version = "1", features = ["full"] } -tower = { version = "0.4", features = ["util"] } tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/examples/compression/Cargo.toml b/examples/compression/Cargo.toml index d5fdcf8e..f6aa4427 100644 --- a/examples/compression/Cargo.toml +++ b/examples/compression/Cargo.toml @@ -6,7 +6,6 @@ publish = false [dependencies] axum = { path = "../../axum" } -axum-extra = { path = "../../axum-extra", features = ["typed-header"] } serde_json = "1" tokio = { version = "1", features = ["macros", "rt-multi-thread"] } tower = "0.4" diff --git a/examples/consume-body-in-extractor-or-middleware/Cargo.toml b/examples/consume-body-in-extractor-or-middleware/Cargo.toml index 9aeb864d..66885885 100644 --- a/examples/consume-body-in-extractor-or-middleware/Cargo.toml +++ b/examples/consume-body-in-extractor-or-middleware/Cargo.toml @@ -7,9 +7,6 @@ publish = false [dependencies] axum = { path = "../../axum" } http-body-util = "0.1.0" -hyper = "1.0.0" tokio = { version = "1.0", features = ["full"] } -tower = "0.4" -tower-http = { version = "0.5.0", features = ["map-request-body", "util"] } tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/examples/customize-path-rejection/Cargo.toml b/examples/customize-path-rejection/Cargo.toml index 8f5b1e44..c1c4884d 100644 --- a/examples/customize-path-rejection/Cargo.toml +++ b/examples/customize-path-rejection/Cargo.toml @@ -7,7 +7,6 @@ publish = false [dependencies] axum = { path = "../../axum" } serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0" tokio = { version = "1.0", features = ["full"] } tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/examples/diesel-async-postgres/Cargo.toml b/examples/diesel-async-postgres/Cargo.toml index d86db151..a79a2521 100644 --- a/examples/diesel-async-postgres/Cargo.toml +++ b/examples/diesel-async-postgres/Cargo.toml @@ -10,7 +10,6 @@ bb8 = "0.8" diesel = "2" diesel-async = { version = "0.3", features = ["postgres", "bb8"] } serde = { version = "1.0", features = ["derive"] } -serde_json = "1" tokio = { version = "1.0", features = ["full"] } tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/examples/diesel-postgres/Cargo.toml b/examples/diesel-postgres/Cargo.toml index ff42a0db..e7566522 100644 --- a/examples/diesel-postgres/Cargo.toml +++ b/examples/diesel-postgres/Cargo.toml @@ -10,7 +10,6 @@ deadpool-diesel = { version = "0.4.1", features = ["postgres"] } diesel = { version = "2", features = ["postgres"] } diesel_migrations = "2" serde = { version = "1.0", features = ["derive"] } -serde_json = "1" tokio = { version = "1.0", features = ["full"] } tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/examples/global-404-handler/Cargo.toml b/examples/global-404-handler/Cargo.toml index 9848d9e8..a453cab5 100644 --- a/examples/global-404-handler/Cargo.toml +++ b/examples/global-404-handler/Cargo.toml @@ -7,6 +7,5 @@ publish = false [dependencies] axum = { path = "../../axum" } tokio = { version = "1.0", features = ["full"] } -tower = { version = "0.4", features = ["util"] } tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/examples/graceful-shutdown/Cargo.toml b/examples/graceful-shutdown/Cargo.toml index 86dfd527..69688ac9 100644 --- a/examples/graceful-shutdown/Cargo.toml +++ b/examples/graceful-shutdown/Cargo.toml @@ -6,10 +6,6 @@ publish = false [dependencies] axum = { path = "../../axum", features = ["tracing"] } -hyper = { version = "1.0", features = [] } -hyper-util = { version = "0.1", features = ["tokio", "server-auto", "http1"] } tokio = { version = "1.0", features = ["full"] } -tower = { version = "0.4", features = ["util"] } tower-http = { version = "0.5", features = ["timeout", "trace"] } -tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/examples/key-value-store/Cargo.toml b/examples/key-value-store/Cargo.toml index c23b28d2..60277fee 100644 --- a/examples/key-value-store/Cargo.toml +++ b/examples/key-value-store/Cargo.toml @@ -15,6 +15,5 @@ tower-http = { version = "0.5.0", features = [ "limit", "trace", ] } -tower-layer = "0.3.2" tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/examples/low-level-rustls/Cargo.toml b/examples/low-level-rustls/Cargo.toml index 3975fcb9..1eaf04b3 100644 --- a/examples/low-level-rustls/Cargo.toml +++ b/examples/low-level-rustls/Cargo.toml @@ -12,7 +12,6 @@ hyper-util = { version = "0.1" } rustls-pemfile = "1.0.4" tokio = { version = "1", features = ["full"] } tokio-rustls = "0.24.1" -tower = { version = "0.4", features = ["make"] } tower-service = "0.3.2" tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/examples/print-request-response/Cargo.toml b/examples/print-request-response/Cargo.toml index a314b5b7..d6e064bb 100644 --- a/examples/print-request-response/Cargo.toml +++ b/examples/print-request-response/Cargo.toml @@ -7,8 +7,6 @@ publish = false [dependencies] axum = { path = "../../axum" } http-body-util = "0.1.0" -hyper = { version = "1.0.0", features = ["full"] } tokio = { version = "1.0", features = ["full"] } -tower = { version = "0.4", features = ["util", "filter"] } tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/examples/query-params-with-empty-strings/Cargo.toml b/examples/query-params-with-empty-strings/Cargo.toml index 7a52e98d..8cc8f1f5 100644 --- a/examples/query-params-with-empty-strings/Cargo.toml +++ b/examples/query-params-with-empty-strings/Cargo.toml @@ -7,7 +7,6 @@ publish = false [dependencies] axum = { path = "../../axum" } http-body-util = "0.1.0" -hyper = "1.0.0" serde = { version = "1.0", features = ["derive"] } tokio = { version = "1.0", features = ["full"] } tower = { version = "0.4", features = ["util"] } diff --git a/examples/readme/Cargo.toml b/examples/readme/Cargo.toml index 4a79c9bb..17669567 100644 --- a/examples/readme/Cargo.toml +++ b/examples/readme/Cargo.toml @@ -7,7 +7,6 @@ publish = false [dependencies] axum = { path = "../../axum" } serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0.68" tokio = { version = "1.0", features = ["full"] } tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/examples/rest-grpc-multiplex/Cargo.toml b/examples/rest-grpc-multiplex/Cargo.toml index 11a6a3a2..e12f8e49 100644 --- a/examples/rest-grpc-multiplex/Cargo.toml +++ b/examples/rest-grpc-multiplex/Cargo.toml @@ -8,13 +8,13 @@ publish = false axum = { path = "../../axum" } futures = "0.3" hyper = { version = "1.0.0", features = ["full"] } -prost = "0.11" -tokio = { version = "1", features = ["full"] } -tonic = { version = "0.9" } -tonic-reflection = "0.9" +#prost = "0.11" +#tokio = { version = "1", features = ["full"] } +#tonic = { version = "0.9" } +#tonic-reflection = "0.9" tower = { version = "0.4", features = ["full"] } -tracing = "0.1" -tracing-subscriber = { version = "0.3", features = ["env-filter"] } +#tracing = "0.1" +#tracing-subscriber = { version = "0.3", features = ["env-filter"] } [build-dependencies] tonic-build = { version = "0.9", features = ["prost"] } diff --git a/examples/simple-router-wasm/Cargo.toml b/examples/simple-router-wasm/Cargo.toml index c3041e4a..d250cc23 100644 --- a/examples/simple-router-wasm/Cargo.toml +++ b/examples/simple-router-wasm/Cargo.toml @@ -14,3 +14,6 @@ axum-extra = { path = "../../axum-extra", default-features = false } futures-executor = "0.3.21" http = "1.0.0" tower-service = "0.3.1" + +[package.metadata.cargo-machete] +ignored = ["axum-extra"] diff --git a/examples/static-file-server/Cargo.toml b/examples/static-file-server/Cargo.toml index 3f41d608..26143acf 100644 --- a/examples/static-file-server/Cargo.toml +++ b/examples/static-file-server/Cargo.toml @@ -6,7 +6,6 @@ publish = false [dependencies] axum = { path = "../../axum" } -axum-extra = { path = "../../axum-extra" } tokio = { version = "1.0", features = ["full"] } tower = { version = "0.4", features = ["util"] } tower-http = { version = "0.5.0", features = ["fs", "trace"] } diff --git a/examples/testing-websockets/Cargo.toml b/examples/testing-websockets/Cargo.toml index afe7b184..0a64468e 100644 --- a/examples/testing-websockets/Cargo.toml +++ b/examples/testing-websockets/Cargo.toml @@ -7,6 +7,5 @@ publish = false [dependencies] axum = { path = "../../axum", features = ["ws"] } futures = "0.3" -hyper = { version = "1.0.0", features = ["full"] } tokio = { version = "1.0", features = ["full"] } tokio-tungstenite = "0.23" diff --git a/examples/testing/Cargo.toml b/examples/testing/Cargo.toml index 00e8132f..946d923c 100644 --- a/examples/testing/Cargo.toml +++ b/examples/testing/Cargo.toml @@ -7,7 +7,6 @@ publish = false [dependencies] axum = { path = "../../axum" } http-body-util = "0.1.0" -hyper = { version = "1.0.0", features = ["full"] } hyper-util = { version = "0.1", features = ["client", "http1", "client-legacy"] } mime = "0.3" serde_json = "1.0" diff --git a/examples/tls-graceful-shutdown/Cargo.toml b/examples/tls-graceful-shutdown/Cargo.toml index 40e48903..18338d38 100644 --- a/examples/tls-graceful-shutdown/Cargo.toml +++ b/examples/tls-graceful-shutdown/Cargo.toml @@ -7,7 +7,6 @@ publish = false [dependencies] axum = { path = "../../axum" } axum-server = { version = "0.6", features = ["tls-rustls"] } -hyper = { version = "0.14", features = ["full"] } tokio = { version = "1", features = ["full"] } tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/examples/unix-domain-socket/Cargo.toml b/examples/unix-domain-socket/Cargo.toml index 7f157c7d..856080ee 100644 --- a/examples/unix-domain-socket/Cargo.toml +++ b/examples/unix-domain-socket/Cargo.toml @@ -11,5 +11,4 @@ hyper = { version = "1.0.0", features = ["full"] } hyper-util = { version = "0.1", features = ["tokio", "server-auto", "http1"] } tokio = { version = "1.0", features = ["full"] } tower = { version = "0.4", features = ["util"] } -tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/examples/validator/Cargo.toml b/examples/validator/Cargo.toml index a1adc075..70216bad 100644 --- a/examples/validator/Cargo.toml +++ b/examples/validator/Cargo.toml @@ -7,7 +7,6 @@ version = "0.1.0" [dependencies] async-trait = "0.1.67" axum = { path = "../../axum" } -http-body = "1.0.0" serde = { version = "1.0", features = ["derive"] } thiserror = "1.0.29" tokio = { version = "1.0", features = ["full"] } diff --git a/examples/websockets/Cargo.toml b/examples/websockets/Cargo.toml index 842a09a3..edcc45e2 100644 --- a/examples/websockets/Cargo.toml +++ b/examples/websockets/Cargo.toml @@ -12,7 +12,6 @@ futures-util = { version = "0.3", default-features = false, features = ["sink", headers = "0.4" tokio = { version = "1.0", features = ["full"] } tokio-tungstenite = "0.23" -tower = { version = "0.4", features = ["util"] } tower-http = { version = "0.5.0", features = ["fs", "trace"] } tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter"] } From 85b6fd49c7c65a9861e6297d65aede15b4f90e28 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Fri, 27 Sep 2024 16:50:52 +0000 Subject: [PATCH 07/16] Upgrade most example dependencies (#2936) --- examples/compression/Cargo.toml | 6 +++--- examples/cors/Cargo.toml | 2 +- examples/diesel-async-postgres/Cargo.toml | 2 +- examples/diesel-postgres/Cargo.toml | 2 +- examples/error-handling/Cargo.toml | 2 +- examples/graceful-shutdown/Cargo.toml | 2 +- examples/handle-head-request/Cargo.toml | 2 +- examples/http-proxy/Cargo.toml | 2 +- examples/jwt/Cargo.toml | 2 +- examples/key-value-store/Cargo.toml | 4 ++-- examples/listen-multiple-addrs/Cargo.toml | 4 ++-- examples/low-level-openssl/Cargo.toml | 2 +- examples/multipart-form/Cargo.toml | 2 +- examples/prometheus-metrics/Cargo.toml | 4 ++-- examples/query-params-with-empty-strings/Cargo.toml | 2 +- examples/reqwest-response/Cargo.toml | 2 +- examples/rest-grpc-multiplex/Cargo.toml | 2 +- examples/serve-with-hyper/Cargo.toml | 2 +- examples/sqlx-postgres/Cargo.toml | 2 +- examples/sse/Cargo.toml | 4 ++-- examples/static-file-server/Cargo.toml | 4 ++-- examples/templates-minijinja/Cargo.toml | 2 +- examples/templates/Cargo.toml | 2 +- examples/testing-websockets/Cargo.toml | 2 +- examples/testing/Cargo.toml | 4 ++-- examples/tls-graceful-shutdown/Cargo.toml | 2 +- examples/tls-rustls/Cargo.toml | 2 +- examples/todos/Cargo.toml | 4 ++-- examples/tokio-postgres/Cargo.toml | 4 ++-- examples/tokio-redis/Cargo.toml | 6 +++--- examples/tracing-aka-logging/Cargo.toml | 2 +- examples/unix-domain-socket/Cargo.toml | 2 +- examples/validator/Cargo.toml | 2 +- examples/websockets/Cargo.toml | 4 ++-- 34 files changed, 47 insertions(+), 47 deletions(-) diff --git a/examples/compression/Cargo.toml b/examples/compression/Cargo.toml index f6aa4427..a65d9d0d 100644 --- a/examples/compression/Cargo.toml +++ b/examples/compression/Cargo.toml @@ -8,14 +8,14 @@ publish = false axum = { path = "../../axum" } serde_json = "1" tokio = { version = "1", features = ["macros", "rt-multi-thread"] } -tower = "0.4" -tower-http = { version = "0.5", features = ["compression-full", "decompression-full"] } +tower = "0.5.1" +tower-http = { version = "0.6.1", features = ["compression-full", "decompression-full"] } tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter"] } [dev-dependencies] assert-json-diff = "2.0" -brotli = "3.4" +brotli = "6.0" flate2 = "1" http = "1" zstd = "0.13" diff --git a/examples/cors/Cargo.toml b/examples/cors/Cargo.toml index 5d5d2eda..654538fa 100644 --- a/examples/cors/Cargo.toml +++ b/examples/cors/Cargo.toml @@ -7,4 +7,4 @@ publish = false [dependencies] axum = { path = "../../axum" } tokio = { version = "1.0", features = ["full"] } -tower-http = { version = "0.5.0", features = ["cors"] } +tower-http = { version = "0.6.1", features = ["cors"] } diff --git a/examples/diesel-async-postgres/Cargo.toml b/examples/diesel-async-postgres/Cargo.toml index a79a2521..efec3440 100644 --- a/examples/diesel-async-postgres/Cargo.toml +++ b/examples/diesel-async-postgres/Cargo.toml @@ -8,7 +8,7 @@ publish = false axum = { path = "../../axum", features = ["macros"] } bb8 = "0.8" diesel = "2" -diesel-async = { version = "0.3", features = ["postgres", "bb8"] } +diesel-async = { version = "0.5", features = ["postgres", "bb8"] } serde = { version = "1.0", features = ["derive"] } tokio = { version = "1.0", features = ["full"] } tracing = "0.1" diff --git a/examples/diesel-postgres/Cargo.toml b/examples/diesel-postgres/Cargo.toml index e7566522..a68b9df8 100644 --- a/examples/diesel-postgres/Cargo.toml +++ b/examples/diesel-postgres/Cargo.toml @@ -6,7 +6,7 @@ publish = false [dependencies] axum = { path = "../../axum", features = ["macros"] } -deadpool-diesel = { version = "0.4.1", features = ["postgres"] } +deadpool-diesel = { version = "0.6.1", features = ["postgres"] } diesel = { version = "2", features = ["postgres"] } diesel_migrations = "2" serde = { version = "1.0", features = ["derive"] } diff --git a/examples/error-handling/Cargo.toml b/examples/error-handling/Cargo.toml index 26fc3b98..7aebc903 100644 --- a/examples/error-handling/Cargo.toml +++ b/examples/error-handling/Cargo.toml @@ -8,6 +8,6 @@ publish = false axum = { path = "../../axum", features = ["macros"] } serde = { version = "1.0", features = ["derive"] } tokio = { version = "1.0", features = ["full"] } -tower-http = { version = "0.5", features = ["trace"] } +tower-http = { version = "0.6.1", features = ["trace"] } tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/examples/graceful-shutdown/Cargo.toml b/examples/graceful-shutdown/Cargo.toml index 69688ac9..c7a57274 100644 --- a/examples/graceful-shutdown/Cargo.toml +++ b/examples/graceful-shutdown/Cargo.toml @@ -7,5 +7,5 @@ publish = false [dependencies] axum = { path = "../../axum", features = ["tracing"] } tokio = { version = "1.0", features = ["full"] } -tower-http = { version = "0.5", features = ["timeout", "trace"] } +tower-http = { version = "0.6.1", features = ["timeout", "trace"] } tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/examples/handle-head-request/Cargo.toml b/examples/handle-head-request/Cargo.toml index 83a8a66e..8497b089 100644 --- a/examples/handle-head-request/Cargo.toml +++ b/examples/handle-head-request/Cargo.toml @@ -11,4 +11,4 @@ tokio = { version = "1.0", features = ["full"] } [dev-dependencies] http-body-util = "0.1.0" hyper = { version = "1.0.0", features = ["full"] } -tower = { version = "0.4", features = ["util"] } +tower = { version = "0.5.1", features = ["util"] } diff --git a/examples/http-proxy/Cargo.toml b/examples/http-proxy/Cargo.toml index 63854471..8dc2f195 100644 --- a/examples/http-proxy/Cargo.toml +++ b/examples/http-proxy/Cargo.toml @@ -9,6 +9,6 @@ axum = { path = "../../axum" } hyper = { version = "1", features = ["full"] } hyper-util = "0.1.1" tokio = { version = "1.0", features = ["full"] } -tower = { version = "0.4", features = ["make", "util"] } +tower = { version = "0.5.1", features = ["make", "util"] } tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/examples/jwt/Cargo.toml b/examples/jwt/Cargo.toml index b0c76c25..54378fe3 100644 --- a/examples/jwt/Cargo.toml +++ b/examples/jwt/Cargo.toml @@ -7,7 +7,7 @@ publish = false [dependencies] axum = { path = "../../axum" } axum-extra = { path = "../../axum-extra", features = ["typed-header"] } -jsonwebtoken = "8.0" +jsonwebtoken = "9.3" once_cell = "1.8" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" diff --git a/examples/key-value-store/Cargo.toml b/examples/key-value-store/Cargo.toml index 60277fee..ccd28c25 100644 --- a/examples/key-value-store/Cargo.toml +++ b/examples/key-value-store/Cargo.toml @@ -7,8 +7,8 @@ publish = false [dependencies] axum = { path = "../../axum" } tokio = { version = "1.0", features = ["full"] } -tower = { version = "0.4", features = ["util", "timeout", "load-shed", "limit"] } -tower-http = { version = "0.5.0", features = [ +tower = { version = "0.5.1", features = ["util", "timeout", "load-shed", "limit"] } +tower-http = { version = "0.6.1", features = [ "add-extension", "auth", "compression-full", diff --git a/examples/listen-multiple-addrs/Cargo.toml b/examples/listen-multiple-addrs/Cargo.toml index 8940b943..ed146ca5 100644 --- a/examples/listen-multiple-addrs/Cargo.toml +++ b/examples/listen-multiple-addrs/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "listen-multiple-addrs" +name = "example-listen-multiple-addrs" version = "0.1.0" edition = "2021" publish = false @@ -9,4 +9,4 @@ axum = { path = "../../axum" } hyper = { version = "1.0.0", features = ["full"] } hyper-util = { version = "0.1", features = ["tokio", "server-auto", "http1"] } tokio = { version = "1", features = ["full"] } -tower = { version = "0.4", features = ["util"] } +tower = { version = "0.5.1", features = ["util"] } diff --git a/examples/low-level-openssl/Cargo.toml b/examples/low-level-openssl/Cargo.toml index c5247dec..a74a950e 100644 --- a/examples/low-level-openssl/Cargo.toml +++ b/examples/low-level-openssl/Cargo.toml @@ -12,6 +12,6 @@ hyper-util = { version = "0.1" } openssl = "0.10" tokio = { version = "1", features = ["full"] } tokio-openssl = "0.6" -tower = { version = "0.4", features = ["make"] } +tower = { version = "0.5.1", features = ["make"] } tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/examples/multipart-form/Cargo.toml b/examples/multipart-form/Cargo.toml index d93b9c08..143154e8 100644 --- a/examples/multipart-form/Cargo.toml +++ b/examples/multipart-form/Cargo.toml @@ -7,6 +7,6 @@ publish = false [dependencies] axum = { path = "../../axum", features = ["multipart"] } tokio = { version = "1.0", features = ["full"] } -tower-http = { version = "0.5.0", features = ["limit", "trace"] } +tower-http = { version = "0.6.1", features = ["limit", "trace"] } tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/examples/prometheus-metrics/Cargo.toml b/examples/prometheus-metrics/Cargo.toml index a30e4436..56ccdd05 100644 --- a/examples/prometheus-metrics/Cargo.toml +++ b/examples/prometheus-metrics/Cargo.toml @@ -6,8 +6,8 @@ publish = false [dependencies] axum = { path = "../../axum" } -metrics = { version = "0.22", default-features = false } -metrics-exporter-prometheus = { version = "0.13", default-features = false } +metrics = { version = "0.23", default-features = false } +metrics-exporter-prometheus = { version = "0.15", default-features = false } tokio = { version = "1.0", features = ["full"] } tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/examples/query-params-with-empty-strings/Cargo.toml b/examples/query-params-with-empty-strings/Cargo.toml index 8cc8f1f5..6dde9a3a 100644 --- a/examples/query-params-with-empty-strings/Cargo.toml +++ b/examples/query-params-with-empty-strings/Cargo.toml @@ -9,4 +9,4 @@ axum = { path = "../../axum" } http-body-util = "0.1.0" serde = { version = "1.0", features = ["derive"] } tokio = { version = "1.0", features = ["full"] } -tower = { version = "0.4", features = ["util"] } +tower = { version = "0.5.1", features = ["util"] } diff --git a/examples/reqwest-response/Cargo.toml b/examples/reqwest-response/Cargo.toml index cfb91bdc..3ea740e3 100644 --- a/examples/reqwest-response/Cargo.toml +++ b/examples/reqwest-response/Cargo.toml @@ -9,6 +9,6 @@ axum = { path = "../../axum" } reqwest = { version = "0.12", features = ["stream"] } tokio = { version = "1.0", features = ["full"] } tokio-stream = "0.1" -tower-http = { version = "0.5.0", features = ["trace"] } +tower-http = { version = "0.6.1", features = ["trace"] } tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/examples/rest-grpc-multiplex/Cargo.toml b/examples/rest-grpc-multiplex/Cargo.toml index e12f8e49..69ece363 100644 --- a/examples/rest-grpc-multiplex/Cargo.toml +++ b/examples/rest-grpc-multiplex/Cargo.toml @@ -12,7 +12,7 @@ hyper = { version = "1.0.0", features = ["full"] } #tokio = { version = "1", features = ["full"] } #tonic = { version = "0.9" } #tonic-reflection = "0.9" -tower = { version = "0.4", features = ["full"] } +tower = { version = "0.5.1", features = ["full"] } #tracing = "0.1" #tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/examples/serve-with-hyper/Cargo.toml b/examples/serve-with-hyper/Cargo.toml index 06f46070..81553eb0 100644 --- a/examples/serve-with-hyper/Cargo.toml +++ b/examples/serve-with-hyper/Cargo.toml @@ -9,4 +9,4 @@ axum = { path = "../../axum" } hyper = { version = "1.0", features = [] } hyper-util = { version = "0.1", features = ["tokio", "server-auto", "http1"] } tokio = { version = "1.0", features = ["full"] } -tower = { version = "0.4", features = ["util"] } +tower = { version = "0.5.1", features = ["util"] } diff --git a/examples/sqlx-postgres/Cargo.toml b/examples/sqlx-postgres/Cargo.toml index 3bc40302..0a0c4376 100644 --- a/examples/sqlx-postgres/Cargo.toml +++ b/examples/sqlx-postgres/Cargo.toml @@ -10,4 +10,4 @@ tokio = { version = "1.0", features = ["full"] } tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter"] } -sqlx = { version = "0.7", features = ["runtime-tokio-rustls", "any", "postgres"] } +sqlx = { version = "0.8", features = ["runtime-tokio-rustls", "any", "postgres"] } diff --git a/examples/sse/Cargo.toml b/examples/sse/Cargo.toml index b2b33159..138820db 100644 --- a/examples/sse/Cargo.toml +++ b/examples/sse/Cargo.toml @@ -11,11 +11,11 @@ futures = "0.3" headers = "0.4" tokio = { version = "1.0", features = ["full"] } tokio-stream = "0.1" -tower-http = { version = "0.5.0", features = ["fs", "trace"] } +tower-http = { version = "0.6.1", features = ["fs", "trace"] } tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter"] } [dev-dependencies] eventsource-stream = "0.2" reqwest = { version = "0.12", features = ["stream"] } -reqwest-eventsource = "0.5" +reqwest-eventsource = "0.6" diff --git a/examples/static-file-server/Cargo.toml b/examples/static-file-server/Cargo.toml index 26143acf..ce195543 100644 --- a/examples/static-file-server/Cargo.toml +++ b/examples/static-file-server/Cargo.toml @@ -7,7 +7,7 @@ publish = false [dependencies] axum = { path = "../../axum" } tokio = { version = "1.0", features = ["full"] } -tower = { version = "0.4", features = ["util"] } -tower-http = { version = "0.5.0", features = ["fs", "trace"] } +tower = { version = "0.5.1", features = ["util"] } +tower-http = { version = "0.6.1", features = ["fs", "trace"] } tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/examples/templates-minijinja/Cargo.toml b/examples/templates-minijinja/Cargo.toml index 9b525a8c..692ea0ca 100644 --- a/examples/templates-minijinja/Cargo.toml +++ b/examples/templates-minijinja/Cargo.toml @@ -6,5 +6,5 @@ publish = false [dependencies] axum = { path = "../../axum" } -minijinja = "1.0.11" +minijinja = "2.3.1" tokio = { version = "1.0", features = ["full"] } diff --git a/examples/templates/Cargo.toml b/examples/templates/Cargo.toml index 2f5aba27..6cba0946 100644 --- a/examples/templates/Cargo.toml +++ b/examples/templates/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" publish = false [dependencies] -askama = "0.11" +askama = "0.12" axum = { path = "../../axum" } tokio = { version = "1.0", features = ["full"] } tracing = "0.1" diff --git a/examples/testing-websockets/Cargo.toml b/examples/testing-websockets/Cargo.toml index 0a64468e..31ed2601 100644 --- a/examples/testing-websockets/Cargo.toml +++ b/examples/testing-websockets/Cargo.toml @@ -8,4 +8,4 @@ publish = false axum = { path = "../../axum", features = ["ws"] } futures = "0.3" tokio = { version = "1.0", features = ["full"] } -tokio-tungstenite = "0.23" +tokio-tungstenite = "0.24" diff --git a/examples/testing/Cargo.toml b/examples/testing/Cargo.toml index 946d923c..811e4f60 100644 --- a/examples/testing/Cargo.toml +++ b/examples/testing/Cargo.toml @@ -11,9 +11,9 @@ hyper-util = { version = "0.1", features = ["client", "http1", "client-legacy"] mime = "0.3" serde_json = "1.0" tokio = { version = "1.0", features = ["full"] } -tower-http = { version = "0.5.0", features = ["trace"] } +tower-http = { version = "0.6.1", features = ["trace"] } tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter"] } [dev-dependencies] -tower = { version = "0.4", features = ["util"] } +tower = { version = "0.5.1", features = ["util"] } diff --git a/examples/tls-graceful-shutdown/Cargo.toml b/examples/tls-graceful-shutdown/Cargo.toml index 18338d38..15b3b73b 100644 --- a/examples/tls-graceful-shutdown/Cargo.toml +++ b/examples/tls-graceful-shutdown/Cargo.toml @@ -6,7 +6,7 @@ publish = false [dependencies] axum = { path = "../../axum" } -axum-server = { version = "0.6", features = ["tls-rustls"] } +axum-server = { version = "0.7", features = ["tls-rustls"] } tokio = { version = "1", features = ["full"] } tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/examples/tls-rustls/Cargo.toml b/examples/tls-rustls/Cargo.toml index 4c255c27..9b976f16 100644 --- a/examples/tls-rustls/Cargo.toml +++ b/examples/tls-rustls/Cargo.toml @@ -6,7 +6,7 @@ publish = false [dependencies] axum = { path = "../../axum" } -axum-server = { version = "0.6", features = ["tls-rustls"] } +axum-server = { version = "0.7", features = ["tls-rustls"] } tokio = { version = "1", features = ["full"] } tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/examples/todos/Cargo.toml b/examples/todos/Cargo.toml index dbd8b712..127fbee4 100644 --- a/examples/todos/Cargo.toml +++ b/examples/todos/Cargo.toml @@ -8,8 +8,8 @@ publish = false axum = { path = "../../axum" } serde = { version = "1.0", features = ["derive"] } tokio = { version = "1.0", features = ["full"] } -tower = { version = "0.4", features = ["util", "timeout"] } -tower-http = { version = "0.5.0", features = ["add-extension", "trace"] } +tower = { version = "0.5.1", features = ["util", "timeout"] } +tower-http = { version = "0.6.1", features = ["add-extension", "trace"] } tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter"] } uuid = { version = "1.0", features = ["serde", "v4"] } diff --git a/examples/tokio-postgres/Cargo.toml b/examples/tokio-postgres/Cargo.toml index 74806044..e14520d2 100644 --- a/examples/tokio-postgres/Cargo.toml +++ b/examples/tokio-postgres/Cargo.toml @@ -6,8 +6,8 @@ publish = false [dependencies] axum = { path = "../../axum" } -bb8 = "0.7.1" -bb8-postgres = "0.7.0" +bb8 = "0.8.5" +bb8-postgres = "0.8.1" tokio = { version = "1.0", features = ["full"] } tokio-postgres = "0.7.2" tracing = "0.1" diff --git a/examples/tokio-redis/Cargo.toml b/examples/tokio-redis/Cargo.toml index fb276849..86d8513b 100644 --- a/examples/tokio-redis/Cargo.toml +++ b/examples/tokio-redis/Cargo.toml @@ -6,9 +6,9 @@ publish = false [dependencies] axum = { path = "../../axum" } -bb8 = "0.7.1" -bb8-redis = "0.14.0" -redis = "0.24.0" +bb8 = "0.8.5" +bb8-redis = "0.17.0" +redis = "0.27.2" tokio = { version = "1.0", features = ["full"] } tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/examples/tracing-aka-logging/Cargo.toml b/examples/tracing-aka-logging/Cargo.toml index 4004cd59..3d120472 100644 --- a/examples/tracing-aka-logging/Cargo.toml +++ b/examples/tracing-aka-logging/Cargo.toml @@ -7,6 +7,6 @@ publish = false [dependencies] axum = { path = "../../axum", features = ["tracing"] } tokio = { version = "1.0", features = ["full"] } -tower-http = { version = "0.5.0", features = ["trace"] } +tower-http = { version = "0.6.1", features = ["trace"] } tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/examples/unix-domain-socket/Cargo.toml b/examples/unix-domain-socket/Cargo.toml index 856080ee..94ceb040 100644 --- a/examples/unix-domain-socket/Cargo.toml +++ b/examples/unix-domain-socket/Cargo.toml @@ -10,5 +10,5 @@ http-body-util = "0.1" hyper = { version = "1.0.0", features = ["full"] } hyper-util = { version = "0.1", features = ["tokio", "server-auto", "http1"] } tokio = { version = "1.0", features = ["full"] } -tower = { version = "0.4", features = ["util"] } +tower = { version = "0.5.1", features = ["util"] } tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/examples/validator/Cargo.toml b/examples/validator/Cargo.toml index 70216bad..cd518393 100644 --- a/examples/validator/Cargo.toml +++ b/examples/validator/Cargo.toml @@ -12,4 +12,4 @@ thiserror = "1.0.29" tokio = { version = "1.0", features = ["full"] } tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter"] } -validator = { version = "0.14.0", features = ["derive"] } +validator = { version = "0.18.1", features = ["derive"] } diff --git a/examples/websockets/Cargo.toml b/examples/websockets/Cargo.toml index edcc45e2..541d8280 100644 --- a/examples/websockets/Cargo.toml +++ b/examples/websockets/Cargo.toml @@ -11,8 +11,8 @@ futures = "0.3" futures-util = { version = "0.3", default-features = false, features = ["sink", "std"] } headers = "0.4" tokio = { version = "1.0", features = ["full"] } -tokio-tungstenite = "0.23" -tower-http = { version = "0.5.0", features = ["fs", "trace"] } +tokio-tungstenite = "0.24.0" +tower-http = { version = "0.6.1", features = ["fs", "trace"] } tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter"] } From 0a0e438a8be03283525939d9bf7f9fc8ef07e884 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Fri, 27 Sep 2024 19:16:17 +0000 Subject: [PATCH 08/16] docs: Remove manual tables of content (#2921) --- axum/CHANGELOG.md | 3 +++ axum/src/docs/error_handling.md | 7 ------- axum/src/docs/extract.md | 15 --------------- axum/src/docs/middleware.md | 12 ------------ axum/src/docs/response.md | 6 ------ axum/src/lib.rs | 17 ----------------- 6 files changed, 3 insertions(+), 57 deletions(-) diff --git a/axum/CHANGELOG.md b/axum/CHANGELOG.md index 54792597..c9427a63 100644 --- a/axum/CHANGELOG.md +++ b/axum/CHANGELOG.md @@ -8,7 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 # Unreleased - **breaking:** The tuple and tuple_struct `Path` extractor deserializers now check that the number of parameters matches the tuple length exactly ([#2931]) +- **change**: Remove manual tables of content from the documentation, since + rustdoc now generates tables of content in the sidebar ([#2921]) +[#2921]: https://github.com/tokio-rs/axum/pull/2921 [#2931]: https://github.com/tokio-rs/axum/pull/2931 # 0.7.6 diff --git a/axum/src/docs/error_handling.md b/axum/src/docs/error_handling.md index 6993b29a..7d7e14ee 100644 --- a/axum/src/docs/error_handling.md +++ b/axum/src/docs/error_handling.md @@ -1,12 +1,5 @@ Error handling model and utilities -# Table of contents - -- [axum's error handling model](#axums-error-handling-model) -- [Routing to fallible services](#routing-to-fallible-services) -- [Applying fallible middleware](#applying-fallible-middleware) -- [Running extractors for error handling](#running-extractors-for-error-handling) - # axum's error handling model axum is based on [`tower::Service`] which bundles errors through its associated diff --git a/axum/src/docs/extract.md b/axum/src/docs/extract.md index 0389ca3c..a1710958 100644 --- a/axum/src/docs/extract.md +++ b/axum/src/docs/extract.md @@ -1,20 +1,5 @@ Types and traits for extracting data from requests. -# Table of contents - -- [Intro](#intro) -- [Common extractors](#common-extractors) -- [Applying multiple extractors](#applying-multiple-extractors) -- [The order of extractors](#the-order-of-extractors) -- [Optional extractors](#optional-extractors) -- [Customizing extractor responses](#customizing-extractor-responses) -- [Accessing inner errors](#accessing-inner-errors) -- [Defining custom extractors](#defining-custom-extractors) -- [Accessing other extractors in `FromRequest` or `FromRequestParts` implementations](#accessing-other-extractors-in-fromrequest-or-fromrequestparts-implementations) -- [Request body limits](#request-body-limits) -- [Wrapping extractors](#wrapping-extractors) -- [Logging rejections](#logging-rejections) - # Intro A handler function is an async function that takes any number of diff --git a/axum/src/docs/middleware.md b/axum/src/docs/middleware.md index 85731414..3a902372 100644 --- a/axum/src/docs/middleware.md +++ b/axum/src/docs/middleware.md @@ -1,15 +1,3 @@ -# Table of contents - -- [Intro](#intro) -- [Applying middleware](#applying-middleware) -- [Commonly used middleware](#commonly-used-middleware) -- [Ordering](#ordering) -- [Writing middleware](#writing-middleware) -- [Routing to services/middleware and backpressure](#routing-to-servicesmiddleware-and-backpressure) -- [Accessing state in middleware](#accessing-state-in-middleware) -- [Passing state from middleware to handlers](#passing-state-from-middleware-to-handlers) -- [Rewriting request URI in middleware](#rewriting-request-uri-in-middleware) - # Intro axum is unique in that it doesn't have its own bespoke middleware system and diff --git a/axum/src/docs/response.md b/axum/src/docs/response.md index 67695632..c0974fb6 100644 --- a/axum/src/docs/response.md +++ b/axum/src/docs/response.md @@ -1,11 +1,5 @@ Types and traits for generating responses. -# Table of contents - -- [Building responses](#building-responses) -- [Returning different response types](#returning-different-response-types) -- [Regarding `impl IntoResponse`](#regarding-impl-intoresponse) - # Building responses Anything that implements [`IntoResponse`] can be returned from a handler. axum diff --git a/axum/src/lib.rs b/axum/src/lib.rs index 7d0d3802..29796229 100644 --- a/axum/src/lib.rs +++ b/axum/src/lib.rs @@ -1,22 +1,5 @@ //! axum is a web application framework that focuses on ergonomics and modularity. //! -//! # Table of contents -//! -//! - [High-level features](#high-level-features) -//! - [Compatibility](#compatibility) -//! - [Example](#example) -//! - [Routing](#routing) -//! - [Handlers](#handlers) -//! - [Extractors](#extractors) -//! - [Responses](#responses) -//! - [Error handling](#error-handling) -//! - [Middleware](#middleware) -//! - [Sharing state with handlers](#sharing-state-with-handlers) -//! - [Building integrations for axum](#building-integrations-for-axum) -//! - [Required dependencies](#required-dependencies) -//! - [Examples](#examples) -//! - [Feature flags](#feature-flags) -//! //! # High-level features //! //! - Route requests to handlers with a macro-free API. From 6ec3a51f2dfb989f19c7ba7d5afe48b36c893a3b Mon Sep 17 00:00:00 2001 From: Sabrina Jewson Date: Sun, 22 Sep 2024 12:32:59 +0100 Subject: [PATCH 09/16] Clarify some subtleties of routing (#2896) --- axum/src/docs/routing/fallback.md | 6 +++++- axum/src/docs/routing/nest.md | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/axum/src/docs/routing/fallback.md b/axum/src/docs/routing/fallback.md index 27fb76a5..a864b7a4 100644 --- a/axum/src/docs/routing/fallback.md +++ b/axum/src/docs/routing/fallback.md @@ -23,7 +23,11 @@ async fn fallback(uri: Uri) -> (StatusCode, String) { Fallbacks only apply to routes that aren't matched by anything in the router. If a handler is matched by a request but returns 404 the -fallback is not called. +fallback is not called. Note that this applies to [`MethodRouter`]s too: if the +request hits a valid path but the [`MethodRouter`] does not have an appropriate +method handler installed, the fallback is not called (use +[`MethodRouter::fallback`] for this purpose instead). + # Handling all requests without other routes diff --git a/axum/src/docs/routing/nest.md b/axum/src/docs/routing/nest.md index 3151729e..845072f0 100644 --- a/axum/src/docs/routing/nest.md +++ b/axum/src/docs/routing/nest.md @@ -82,6 +82,11 @@ let app = Router::new() # let _: Router = app; ``` +Additionally, while the wildcard route `/foo/*rest` will not match the +paths `/foo` or `/foo/`, a nested router at `/foo` will match the path `/foo` +(but not `/foo/`), and a nested router at `/foo/` will match the path `/foo/` +(but not `/foo`). + # Fallbacks If a nested router doesn't have its own fallback then it will inherit the From 4fc0641874fa73d34b64b89e715937498eaec0ee Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Tue, 24 Sep 2024 21:50:53 +0000 Subject: [PATCH 10/16] Upgrade private dependencies (#2935) --- axum/Cargo.toml | 6 +++--- examples/http-proxy/Cargo.toml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/axum/Cargo.toml b/axum/Cargo.toml index 4ef57819..b4cd4363 100644 --- a/axum/Cargo.toml +++ b/axum/Cargo.toml @@ -63,7 +63,7 @@ tower-service = "0.3" # optional dependencies axum-macros = { path = "../axum-macros", version = "0.4.2", optional = true } -base64 = { version = "0.21.0", optional = true } +base64 = { version = "0.22.1", optional = true } hyper = { version = "1.1.0", optional = true } hyper-util = { version = "0.1.3", features = ["tokio", "server", "service"], optional = true } multer = { version = "3.0.0", optional = true } @@ -72,7 +72,7 @@ serde_path_to_error = { version = "0.1.8", optional = true } serde_urlencoded = { version = "0.7", optional = true } sha1 = { version = "0.10", optional = true } tokio = { package = "tokio", version = "1.25.0", features = ["time"], optional = true } -tokio-tungstenite = { version = "0.23", optional = true } +tokio-tungstenite = { version = "0.24.0", optional = true } tracing = { version = "0.1", default-features = false, optional = true } [dependencies.tower-http] @@ -121,7 +121,7 @@ serde_json = "1.0" time = { version = "0.3", features = ["serde-human-readable"] } tokio = { package = "tokio", version = "1.25.0", features = ["macros", "rt", "rt-multi-thread", "net", "test-util"] } tokio-stream = "0.1" -tokio-tungstenite = "0.23" +tokio-tungstenite = "0.24.0" tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["json"] } uuid = { version = "1.0", features = ["serde", "v4"] } diff --git a/examples/http-proxy/Cargo.toml b/examples/http-proxy/Cargo.toml index aa607002..63854471 100644 --- a/examples/http-proxy/Cargo.toml +++ b/examples/http-proxy/Cargo.toml @@ -9,6 +9,6 @@ axum = { path = "../../axum" } hyper = { version = "1", features = ["full"] } hyper-util = "0.1.1" tokio = { version = "1.0", features = ["full"] } -tower = { version = "0.4", features = ["make"] } +tower = { version = "0.4", features = ["make", "util"] } tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter"] } From 6f5607785d2dc7ea0ede03c11914d32cdb305953 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Wed, 25 Sep 2024 07:44:35 +0000 Subject: [PATCH 11/16] core: Fix compile errors from __log_rejection (#2933) --- axum-core/src/lib.rs | 5 +++++ axum-core/src/macros.rs | 6 +++--- axum-extra/Cargo.toml | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/axum-core/src/lib.rs b/axum-core/src/lib.rs index cd1dc2ee..134c566b 100644 --- a/axum-core/src/lib.rs +++ b/axum-core/src/lib.rs @@ -50,6 +50,11 @@ #[macro_use] pub(crate) mod macros; +#[doc(hidden)] // macro helpers +pub mod __private { + #[cfg(feature = "tracing")] + pub use tracing; +} mod error; mod ext_traits; diff --git a/axum-core/src/macros.rs b/axum-core/src/macros.rs index 7d723818..aa99ba40 100644 --- a/axum-core/src/macros.rs +++ b/axum-core/src/macros.rs @@ -9,12 +9,12 @@ macro_rules! __log_rejection { status = $status:expr, ) => { { - tracing::event!( + $crate::__private::tracing::event!( target: "axum::rejection", - tracing::Level::TRACE, + $crate::__private::tracing::Level::TRACE, status = $status.as_u16(), body = $body_text, - rejection_type = std::any::type_name::<$ty>(), + rejection_type = ::std::any::type_name::<$ty>(), "rejecting request", ); } diff --git a/axum-extra/Cargo.toml b/axum-extra/Cargo.toml index 06aa0766..7a964b00 100644 --- a/axum-extra/Cargo.toml +++ b/axum-extra/Cargo.toml @@ -34,7 +34,7 @@ json-lines = [ multipart = ["dep:multer"] protobuf = ["dep:prost"] query = ["dep:serde_html_form"] -tracing = ["dep:tracing", "axum-core/tracing", "axum/tracing"] +tracing = ["axum-core/tracing", "axum/tracing"] typed-header = ["dep:headers"] typed-routing = ["dep:axum-macros", "dep:percent-encoding", "dep:serde_html_form", "dep:form_urlencoded"] From ac50d7daafad8e0afd206d5aeaca5e33851dc57b Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Fri, 27 Sep 2024 19:16:17 +0000 Subject: [PATCH 12/16] docs: Remove manual tables of content (#2921) --- axum/CHANGELOG.md | 7 +++++++ axum/src/docs/error_handling.md | 7 ------- axum/src/docs/extract.md | 15 --------------- axum/src/docs/middleware.md | 12 ------------ axum/src/docs/response.md | 6 ------ axum/src/lib.rs | 17 ----------------- 6 files changed, 7 insertions(+), 57 deletions(-) diff --git a/axum/CHANGELOG.md b/axum/CHANGELOG.md index 0379672c..acab31cc 100644 --- a/axum/CHANGELOG.md +++ b/axum/CHANGELOG.md @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +# Unreleased + +- **change**: Remove manual tables of content from the documentation, since + rustdoc now generates tables of content in the sidebar ([#2921]) + +[#2921]: https://github.com/tokio-rs/axum/pull/2921 + # 0.7.6 - **change:** Avoid cloning `Arc` during deserialization of `Path` diff --git a/axum/src/docs/error_handling.md b/axum/src/docs/error_handling.md index 6993b29a..7d7e14ee 100644 --- a/axum/src/docs/error_handling.md +++ b/axum/src/docs/error_handling.md @@ -1,12 +1,5 @@ Error handling model and utilities -# Table of contents - -- [axum's error handling model](#axums-error-handling-model) -- [Routing to fallible services](#routing-to-fallible-services) -- [Applying fallible middleware](#applying-fallible-middleware) -- [Running extractors for error handling](#running-extractors-for-error-handling) - # axum's error handling model axum is based on [`tower::Service`] which bundles errors through its associated diff --git a/axum/src/docs/extract.md b/axum/src/docs/extract.md index 0389ca3c..a1710958 100644 --- a/axum/src/docs/extract.md +++ b/axum/src/docs/extract.md @@ -1,20 +1,5 @@ Types and traits for extracting data from requests. -# Table of contents - -- [Intro](#intro) -- [Common extractors](#common-extractors) -- [Applying multiple extractors](#applying-multiple-extractors) -- [The order of extractors](#the-order-of-extractors) -- [Optional extractors](#optional-extractors) -- [Customizing extractor responses](#customizing-extractor-responses) -- [Accessing inner errors](#accessing-inner-errors) -- [Defining custom extractors](#defining-custom-extractors) -- [Accessing other extractors in `FromRequest` or `FromRequestParts` implementations](#accessing-other-extractors-in-fromrequest-or-fromrequestparts-implementations) -- [Request body limits](#request-body-limits) -- [Wrapping extractors](#wrapping-extractors) -- [Logging rejections](#logging-rejections) - # Intro A handler function is an async function that takes any number of diff --git a/axum/src/docs/middleware.md b/axum/src/docs/middleware.md index 85731414..3a902372 100644 --- a/axum/src/docs/middleware.md +++ b/axum/src/docs/middleware.md @@ -1,15 +1,3 @@ -# Table of contents - -- [Intro](#intro) -- [Applying middleware](#applying-middleware) -- [Commonly used middleware](#commonly-used-middleware) -- [Ordering](#ordering) -- [Writing middleware](#writing-middleware) -- [Routing to services/middleware and backpressure](#routing-to-servicesmiddleware-and-backpressure) -- [Accessing state in middleware](#accessing-state-in-middleware) -- [Passing state from middleware to handlers](#passing-state-from-middleware-to-handlers) -- [Rewriting request URI in middleware](#rewriting-request-uri-in-middleware) - # Intro axum is unique in that it doesn't have its own bespoke middleware system and diff --git a/axum/src/docs/response.md b/axum/src/docs/response.md index 67695632..c0974fb6 100644 --- a/axum/src/docs/response.md +++ b/axum/src/docs/response.md @@ -1,11 +1,5 @@ Types and traits for generating responses. -# Table of contents - -- [Building responses](#building-responses) -- [Returning different response types](#returning-different-response-types) -- [Regarding `impl IntoResponse`](#regarding-impl-intoresponse) - # Building responses Anything that implements [`IntoResponse`] can be returned from a handler. axum diff --git a/axum/src/lib.rs b/axum/src/lib.rs index 7d0d3802..29796229 100644 --- a/axum/src/lib.rs +++ b/axum/src/lib.rs @@ -1,22 +1,5 @@ //! axum is a web application framework that focuses on ergonomics and modularity. //! -//! # Table of contents -//! -//! - [High-level features](#high-level-features) -//! - [Compatibility](#compatibility) -//! - [Example](#example) -//! - [Routing](#routing) -//! - [Handlers](#handlers) -//! - [Extractors](#extractors) -//! - [Responses](#responses) -//! - [Error handling](#error-handling) -//! - [Middleware](#middleware) -//! - [Sharing state with handlers](#sharing-state-with-handlers) -//! - [Building integrations for axum](#building-integrations-for-axum) -//! - [Required dependencies](#required-dependencies) -//! - [Examples](#examples) -//! - [Feature flags](#feature-flags) -//! //! # High-level features //! //! - Route requests to handlers with a macro-free API. From fe56a310efbb30b3b178059c48a31d1000ed5f62 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Fri, 27 Sep 2024 21:30:11 +0200 Subject: [PATCH 13/16] Bump versions --- axum-core/CHANGELOG.md | 7 +++++++ axum-core/Cargo.toml | 2 +- axum-extra/Cargo.toml | 4 ++-- axum/CHANGELOG.md | 2 +- axum/Cargo.toml | 4 ++-- 5 files changed, 13 insertions(+), 6 deletions(-) diff --git a/axum-core/CHANGELOG.md b/axum-core/CHANGELOG.md index 464ee314..dc1b9ed5 100644 --- a/axum-core/CHANGELOG.md +++ b/axum-core/CHANGELOG.md @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +# 0.4.5 + +- **fixed:** Compile errors from the internal `__log_rejection` macro under + certain Cargo feature combinations between axum crates ([#2933]) + +[#2933]: https://github.com/tokio-rs/axum/pull/2933 + # 0.4.4 - **added:** Derive `Clone` and `Copy` for `AppendHeaders` ([#2776]) diff --git a/axum-core/Cargo.toml b/axum-core/Cargo.toml index 2d4d0759..f7c31668 100644 --- a/axum-core/Cargo.toml +++ b/axum-core/Cargo.toml @@ -9,7 +9,7 @@ license = "MIT" name = "axum-core" readme = "README.md" repository = "https://github.com/tokio-rs/axum" -version = "0.4.4" # remember to also bump the version that axum and axum-extra depend on +version = "0.4.5" # remember to also bump the version that axum and axum-extra depend on [features] tracing = ["dep:tracing"] diff --git a/axum-extra/Cargo.toml b/axum-extra/Cargo.toml index 7a964b00..7c967749 100644 --- a/axum-extra/Cargo.toml +++ b/axum-extra/Cargo.toml @@ -39,8 +39,8 @@ typed-header = ["dep:headers"] typed-routing = ["dep:axum-macros", "dep:percent-encoding", "dep:serde_html_form", "dep:form_urlencoded"] [dependencies] -axum = { path = "../axum", version = "0.7.6", default-features = false } -axum-core = { path = "../axum-core", version = "0.4.4" } +axum = { path = "../axum", version = "0.7.7", default-features = false } +axum-core = { path = "../axum-core", version = "0.4.5" } bytes = "1.1.0" futures-util = { version = "0.3", default-features = false, features = ["alloc"] } http = "1.0.0" diff --git a/axum/CHANGELOG.md b/axum/CHANGELOG.md index acab31cc..aa9d8067 100644 --- a/axum/CHANGELOG.md +++ b/axum/CHANGELOG.md @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -# Unreleased +# 0.7.7 - **change**: Remove manual tables of content from the documentation, since rustdoc now generates tables of content in the sidebar ([#2921]) diff --git a/axum/Cargo.toml b/axum/Cargo.toml index b4cd4363..263d3a96 100644 --- a/axum/Cargo.toml +++ b/axum/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "axum" -version = "0.7.6" +version = "0.7.7" categories = ["asynchronous", "network-programming", "web-programming::http-server"] description = "Web framework that focuses on ergonomics and modularity" edition = "2021" @@ -42,7 +42,7 @@ __private_docs = ["tower/full", "dep:tower-http"] [dependencies] async-trait = "0.1.67" -axum-core = { path = "../axum-core", version = "0.4.4" } +axum-core = { path = "../axum-core", version = "0.4.5" } bytes = "1.0" futures-util = { version = "0.3", default-features = false, features = ["alloc"] } http = "1.0.0" From 5d8541de6e5fc0970ea7e29ee3605cb730ac0e71 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Fri, 27 Sep 2024 21:16:54 +0000 Subject: [PATCH 14/16] Remove duplication in serving with and without graceful shutdown (#2803) --- axum/src/routing/tests/mod.rs | 3 +- axum/src/serve.rs | 57 +--------------- axum/src/test_helpers/tracing_helpers.rs | 86 +++++++++++++++++------- 3 files changed, 67 insertions(+), 79 deletions(-) diff --git a/axum/src/routing/tests/mod.rs b/axum/src/routing/tests/mod.rs index 144c870d..e9ab56e1 100644 --- a/axum/src/routing/tests/mod.rs +++ b/axum/src/routing/tests/mod.rs @@ -966,7 +966,7 @@ async fn logging_rejections() { rejection_type: String, } - let events = capture_tracing::(|| async { + let events = capture_tracing::(|| async { let app = Router::new() .route("/extension", get(|_: Extension| async {})) .route("/string", post(|_: String| async {})); @@ -987,6 +987,7 @@ async fn logging_rejections() { StatusCode::BAD_REQUEST, ); }) + .with_filter("axum::rejection=trace") .await; assert_eq!( diff --git a/axum/src/serve.rs b/axum/src/serve.rs index e2b974cf..1ba9a145 100644 --- a/axum/src/serve.rs +++ b/axum/src/serve.rs @@ -213,61 +213,8 @@ where type IntoFuture = private::ServeFuture; fn into_future(self) -> Self::IntoFuture { - private::ServeFuture(Box::pin(async move { - let Self { - tcp_listener, - mut make_service, - tcp_nodelay, - _marker: _, - } = self; - - loop { - let (tcp_stream, remote_addr) = match tcp_accept(&tcp_listener).await { - Some(conn) => conn, - None => continue, - }; - - if let Some(nodelay) = tcp_nodelay { - if let Err(err) = tcp_stream.set_nodelay(nodelay) { - trace!("failed to set TCP_NODELAY on incoming connection: {err:#}"); - } - } - - let tcp_stream = TokioIo::new(tcp_stream); - - poll_fn(|cx| make_service.poll_ready(cx)) - .await - .unwrap_or_else(|err| match err {}); - - let tower_service = make_service - .call(IncomingStream { - tcp_stream: &tcp_stream, - remote_addr, - }) - .await - .unwrap_or_else(|err| match err {}) - .map_request(|req: Request| req.map(Body::new)); - - let hyper_service = TowerToHyperService::new(tower_service); - - tokio::spawn(async move { - match Builder::new(TokioExecutor::new()) - // upgrades needed for websockets - .serve_connection_with_upgrades(tcp_stream, hyper_service) - .await - { - Ok(()) => {} - Err(_err) => { - // This error only appears when the client doesn't send a request and - // terminate the connection. - // - // If client sends one request then terminate connection whenever, it doesn't - // appear. - } - } - }); - } - })) + self.with_graceful_shutdown(std::future::pending()) + .into_future() } } diff --git a/axum/src/test_helpers/tracing_helpers.rs b/axum/src/test_helpers/tracing_helpers.rs index 2240717e..96abe510 100644 --- a/axum/src/test_helpers/tracing_helpers.rs +++ b/axum/src/test_helpers/tracing_helpers.rs @@ -1,7 +1,14 @@ use crate::util::AxumMutex; -use std::{future::Future, io, sync::Arc}; +use std::{ + future::{Future, IntoFuture}, + io, + marker::PhantomData, + pin::Pin, + sync::Arc, +}; use serde::{de::DeserializeOwned, Deserialize}; +use tracing::instrument::WithSubscriber; use tracing_subscriber::prelude::*; use tracing_subscriber::{filter::Targets, fmt::MakeWriter}; @@ -14,36 +21,69 @@ pub(crate) struct TracingEvent { } /// Run an async closure and capture the tracing output it produces. -pub(crate) async fn capture_tracing(f: F) -> Vec> +pub(crate) fn capture_tracing(f: F) -> CaptureTracing where - F: Fn() -> Fut, - Fut: Future, T: DeserializeOwned, { - let (make_writer, handle) = TestMakeWriter::new(); + CaptureTracing { + f, + filter: None, + _phantom: PhantomData, + } +} - let subscriber = tracing_subscriber::registry().with( - tracing_subscriber::fmt::layer() - .with_writer(make_writer) - .with_target(true) - .without_time() - .with_ansi(false) - .json() - .flatten_event(false) - .with_filter("axum=trace".parse::().unwrap()), - ); +pub(crate) struct CaptureTracing { + f: F, + filter: Option, + _phantom: PhantomData T>, +} - let guard = tracing::subscriber::set_default(subscriber); +impl CaptureTracing { + pub(crate) fn with_filter(mut self, filter_string: &str) -> Self { + self.filter = Some(filter_string.parse().unwrap()); + self + } +} - f().await; +impl IntoFuture for CaptureTracing +where + F: Fn() -> Fut + Send + Sync + 'static, + Fut: Future + Send, + T: DeserializeOwned, +{ + type Output = Vec>; + type IntoFuture = Pin + Send>>; - drop(guard); + fn into_future(self) -> Self::IntoFuture { + let Self { f, filter, .. } = self; + Box::pin(async move { + let (make_writer, handle) = TestMakeWriter::new(); - handle - .take() - .lines() - .map(|line| serde_json::from_str(line).unwrap()) - .collect() + let filter = filter.unwrap_or_else(|| "axum=trace".parse().unwrap()); + let subscriber = tracing_subscriber::registry().with( + tracing_subscriber::fmt::layer() + .with_writer(make_writer) + .with_target(true) + .without_time() + .with_ansi(false) + .json() + .flatten_event(false) + .with_filter(filter), + ); + + let guard = tracing::subscriber::set_default(subscriber); + + f().with_current_subscriber().await; + + drop(guard); + + handle + .take() + .lines() + .map(|line| serde_json::from_str(line).unwrap()) + .collect() + }) + } } struct TestMakeWriter { From 2542acb24357d7092ecbc6921a02a11a979033d6 Mon Sep 17 00:00:00 2001 From: Nia <7388349+conways-glider@users.noreply.github.com> Date: Sat, 28 Sep 2024 03:25:05 -0600 Subject: [PATCH 15/16] Add request id example (#2912) --- examples/request-id/Cargo.toml | 13 ++++++ examples/request-id/src/main.rs | 81 +++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 examples/request-id/Cargo.toml create mode 100644 examples/request-id/src/main.rs diff --git a/examples/request-id/Cargo.toml b/examples/request-id/Cargo.toml new file mode 100644 index 00000000..22879e08 --- /dev/null +++ b/examples/request-id/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "example-request-id" +version = "0.1.0" +edition = "2021" +publish = false + +[dependencies] +axum = { path = "../../axum" } +tokio = { version = "1.0", features = ["full"] } +tower = "0.5" +tower-http = { version = "0.5", features = ["request-id", "trace"] } +tracing = "0.1" +tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/examples/request-id/src/main.rs b/examples/request-id/src/main.rs new file mode 100644 index 00000000..552d8d4a --- /dev/null +++ b/examples/request-id/src/main.rs @@ -0,0 +1,81 @@ +//! Run with +//! +//! ```not_rust +//! cargo run -p example-request-id +//! ``` + +use axum::{ + http::{HeaderName, Request}, + response::Html, + routing::get, + Router, +}; +use tower::ServiceBuilder; +use tower_http::{ + request_id::{MakeRequestUuid, PropagateRequestIdLayer, SetRequestIdLayer}, + trace::TraceLayer, +}; +use tracing::{error, info, info_span}; +use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; + +const REQUEST_ID_HEADER: &str = "x-request-id"; + +#[tokio::main] +async fn main() { + tracing_subscriber::registry() + .with( + tracing_subscriber::EnvFilter::try_from_default_env().unwrap_or_else(|_| { + // axum logs rejections from built-in extractors with the `axum::rejection` + // target, at `TRACE` level. `axum::rejection=trace` enables showing those events + format!( + "{}=debug,tower_http=debug,axum::rejection=trace", + env!("CARGO_CRATE_NAME") + ) + .into() + }), + ) + .with(tracing_subscriber::fmt::layer()) + .init(); + + let x_request_id = HeaderName::from_static(REQUEST_ID_HEADER); + + let middleware = ServiceBuilder::new() + .layer(SetRequestIdLayer::new( + x_request_id.clone(), + MakeRequestUuid, + )) + .layer( + TraceLayer::new_for_http().make_span_with(|request: &Request<_>| { + // Log the request id as generated. + let request_id = request.headers().get(REQUEST_ID_HEADER); + + match request_id { + Some(request_id) => info_span!( + "http_request", + request_id = ?request_id, + ), + None => { + error!("could not extract request_id"); + info_span!("http_request") + } + } + }), + ) + // send headers from request to response headers + .layer(PropagateRequestIdLayer::new(x_request_id)); + + // build our application with a route + let app = Router::new().route("/", get(handler)).layer(middleware); + + // run it + let listener = tokio::net::TcpListener::bind("127.0.0.1:3000") + .await + .unwrap(); + println!("listening on {}", listener.local_addr().unwrap()); + axum::serve(listener, app).await.unwrap(); +} + +async fn handler() -> Html<&'static str> { + info!("Hello world!"); + Html("

Hello, World!

") +} From e784977aa63bd7928769b00fb620e0a85099b129 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Artur=20Corr=C3=AAa=20Souza?= Date: Sat, 28 Sep 2024 06:34:50 -0300 Subject: [PATCH 16/16] docs: Remove duplicate tower-sessions entry from ECOSYSTEM.md (#2733) --- ECOSYSTEM.md | 1 - 1 file changed, 1 deletion(-) diff --git a/ECOSYSTEM.md b/ECOSYSTEM.md index 9a27ab34..6ec5248e 100644 --- a/ECOSYSTEM.md +++ b/ECOSYSTEM.md @@ -28,7 +28,6 @@ If your project isn't listed here and you would like it to be, please feel free - [aide](https://docs.rs/aide): Code-first Open API documentation generator with [axum integration](https://docs.rs/aide/latest/aide/axum/index.html). - [axum-typed-routing](https://docs.rs/axum-typed-routing/latest/axum_typed_routing/): Statically typed routing macros with OpenAPI generation using aide. - [axum-jsonschema](https://docs.rs/axum-jsonschema/): A `Json` extractor that does JSON schema validation of requests. -- [tower-sessions](https://docs.rs/tower-sessions): Cookie-based sessions. - [axum-login](https://docs.rs/axum-login): Session-based user authentication for axum. - [axum-csrf-sync-pattern](https://crates.io/crates/axum-csrf-sync-pattern): A middleware implementing CSRF STP for AJAX backends and API endpoints. - [axum-otel-metrics](https://github.com/ttys3/axum-otel-metrics/): A axum OpenTelemetry Metrics middleware with prometheus exporter supported.