From 11a543a4092929e119ee99d3863a8dc07a74a648 Mon Sep 17 00:00:00 2001 From: David Pedersen Date: Fri, 24 Mar 2023 15:11:30 +0100 Subject: [PATCH] use tower-http patch --- Cargo.toml | 7 +++++++ axum-core/src/extract/default_body_limit.rs | 6 +++--- axum-core/src/response/into_response.rs | 19 +++++-------------- axum/Cargo.toml | 2 +- axum/src/docs/method_routing/fallback.md | 9 ++------- axum/src/docs/method_routing/merge.md | 4 +--- axum/src/docs/routing/fallback.md | 4 +--- axum/src/docs/routing/merge.md | 4 +--- axum/src/lib.rs | 8 ++------ axum/src/response/redirect.rs | 4 +--- axum/src/response/sse.rs | 4 +--- 11 files changed, 25 insertions(+), 46 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a68aaab1..f94cfd92 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,3 +5,10 @@ default-members = ["axum", "axum-*"] # Example has been deleted, but README.md remains exclude = ["examples/async-graphql"] resolver = "2" + +[patch.crates-io] +# https://github.com/tower-rs/tower-http/pull/348 +tower-http = { git = "https://github.com/tower-rs/tower-http", rev = "8734fc4438828" } + +# for `Frame::map_data` +http-body = { git = "https://github.com/hyperium/http-body", rev = "7bf321acbb422" } diff --git a/axum-core/src/extract/default_body_limit.rs b/axum-core/src/extract/default_body_limit.rs index 5a2cd971..7ca54463 100644 --- a/axum-core/src/extract/default_body_limit.rs +++ b/axum-core/src/extract/default_body_limit.rs @@ -46,7 +46,7 @@ use tower_layer::Layer; /// ``` /// use axum::{Router, routing::post, body::Body, extract::Request}; /// use tower_http::limit::RequestBodyLimitLayer; -/// use http_body::Limited; +/// use http_body_util::Limited; /// /// let app = Router::new() /// .route( @@ -102,7 +102,7 @@ impl DefaultBodyLimit { /// extract::DefaultBodyLimit, /// }; /// use tower_http::limit::RequestBodyLimitLayer; - /// use http_body::Limited; + /// use http_body_util::Limited; /// /// let app: Router<()> = Router::new() /// .route("/", get(|body: Bytes| async {})) @@ -137,7 +137,7 @@ impl DefaultBodyLimit { /// extract::DefaultBodyLimit, /// }; /// use tower_http::limit::RequestBodyLimitLayer; - /// use http_body::Limited; + /// use http_body_util::Limited; /// /// let app: Router<()> = Router::new() /// .route("/", get(|body: Bytes| async {})) diff --git a/axum-core/src/response/into_response.rs b/axum-core/src/response/into_response.rs index b4bf8f6f..6d597068 100644 --- a/axum-core/src/response/into_response.rs +++ b/axum-core/src/response/into_response.rs @@ -58,9 +58,7 @@ use std::{ /// async fn handler() -> Result<(), MyError> { /// Err(MyError::SomethingWentWrong) /// } -/// # async { -/// # hyper::Server::bind(&"".parse().unwrap()).serve(app.into_make_service()).await.unwrap(); -/// # }; +/// # let _: Router = app; /// ``` /// /// Or if you have a custom body type you'll also need to implement @@ -76,6 +74,7 @@ use std::{ /// }; /// use http::HeaderMap; /// use bytes::Bytes; +/// use http_body::Frame; /// use std::{ /// convert::Infallible, /// task::{Poll, Context}, @@ -90,18 +89,10 @@ use std::{ /// type Data = Bytes; /// type Error = Infallible; /// -/// fn poll_data( +/// fn poll_frame( /// self: Pin<&mut Self>, -/// cx: &mut Context<'_> -/// ) -> Poll>> { -/// # unimplemented!() -/// // ... -/// } -/// -/// fn poll_trailers( -/// self: Pin<&mut Self>, -/// cx: &mut Context<'_> -/// ) -> Poll, Self::Error>> { +/// cx: &mut Context<'_>, +/// ) -> Poll, Self::Error>>> { /// # unimplemented!() /// // ... /// } diff --git a/axum/Cargo.toml b/axum/Cargo.toml index 5f5c8ed9..1fe66989 100644 --- a/axum/Cargo.toml +++ b/axum/Cargo.toml @@ -22,7 +22,7 @@ matched-path = [] multipart = ["dep:multer"] original-uri = [] query = ["dep:serde_urlencoded"] -tokio = ["dep:tokio", "hyper/server", "tower/make"] +tokio = ["dep:tokio", "tokio/rt", "tokio/net", "hyper/server", "tower/make"] tower-log = ["tower/log"] ws = ["tokio", "dep:tokio-tungstenite", "dep:sha1", "dep:base64"] diff --git a/axum/src/docs/method_routing/fallback.md b/axum/src/docs/method_routing/fallback.md index 906cbb3b..48be18d3 100644 --- a/axum/src/docs/method_routing/fallback.md +++ b/axum/src/docs/method_routing/fallback.md @@ -18,9 +18,7 @@ let app = Router::new().route("/", handler); async fn fallback(method: Method, uri: Uri) -> (StatusCode, String) { (StatusCode::NOT_FOUND, format!("`{}` not allowed for {}", method, uri)) } -# async { -# hyper::Server::bind(&"".parse().unwrap()).serve(app.into_make_service()).await.unwrap(); -# }; +# let _: Router = app; ``` ## When used with `MethodRouter::merge` @@ -44,10 +42,7 @@ let method_route = one.merge(two); async fn fallback_one() -> impl IntoResponse { /* ... */ } async fn fallback_two() -> impl IntoResponse { /* ... */ } -# let app = axum::Router::new().route("/", method_route); -# async { -# hyper::Server::bind(&"".parse().unwrap()).serve(app.into_make_service()).await.unwrap(); -# }; +# let app: axum::Router = axum::Router::new().route("/", method_route); ``` ## Setting the `Allow` header diff --git a/axum/src/docs/method_routing/merge.md b/axum/src/docs/method_routing/merge.md index 39d74d04..a88ee2d7 100644 --- a/axum/src/docs/method_routing/merge.md +++ b/axum/src/docs/method_routing/merge.md @@ -19,7 +19,5 @@ let app = Router::new().route("/", merged); // Our app now accepts // - GET / // - POST / -# async { -# hyper::Server::bind(&"".parse().unwrap()).serve(app.into_make_service()).await.unwrap(); -# }; +# let _: Router = app; ``` diff --git a/axum/src/docs/routing/fallback.md b/axum/src/docs/routing/fallback.md index f2b5d333..e81d25c1 100644 --- a/axum/src/docs/routing/fallback.md +++ b/axum/src/docs/routing/fallback.md @@ -18,9 +18,7 @@ let app = Router::new() async fn fallback(uri: Uri) -> (StatusCode, String) { (StatusCode::NOT_FOUND, format!("No route for {}", uri)) } -# async { -# hyper::Server::bind(&"".parse().unwrap()).serve(app.into_make_service()).await.unwrap(); -# }; +# let _: Router = app; ``` Fallbacks only apply to routes that aren't matched by anything in the diff --git a/axum/src/docs/routing/merge.md b/axum/src/docs/routing/merge.md index 0e103c83..08136f87 100644 --- a/axum/src/docs/routing/merge.md +++ b/axum/src/docs/routing/merge.md @@ -32,9 +32,7 @@ let app = Router::new() // - GET /users // - GET /users/:id // - POST /teams -# async { -# hyper::Server::bind(&"".parse().unwrap()).serve(app.into_make_service()).await.unwrap(); -# }; +# let _: Router = app; ``` # Merging routers with state diff --git a/axum/src/lib.rs b/axum/src/lib.rs index 9dca510f..c64c7107 100644 --- a/axum/src/lib.rs +++ b/axum/src/lib.rs @@ -308,16 +308,12 @@ //! ```toml //! [dependencies] //! axum = "" -//! hyper = { version = "", features = ["full"] } //! tokio = { version = "", features = ["full"] } //! tower = "" //! ``` //! -//! The `"full"` feature for hyper and tokio isn't strictly necessary but it's -//! the easiest way to get started. -//! -//! Note that [`hyper::Server`] is re-exported by axum so if that's all you need -//! then you don't have to explicitly depend on hyper. +//! The `"full"` feature for tokio isn't strictly necessary but it's the easiest way to get +//! started. //! //! Tower isn't strictly necessary either but helpful for testing. See the //! testing example in the repo to learn more about testing axum apps. diff --git a/axum/src/response/redirect.rs b/axum/src/response/redirect.rs index 4dee5b5c..8bc6eb5e 100644 --- a/axum/src/response/redirect.rs +++ b/axum/src/response/redirect.rs @@ -15,9 +15,7 @@ use http::{header::LOCATION, HeaderValue, StatusCode}; /// let app = Router::new() /// .route("/old", get(|| async { Redirect::permanent("/new") })) /// .route("/new", get(|| async { "Hello!" })); -/// # async { -/// # hyper::Server::bind(&"".parse().unwrap()).serve(app.into_make_service()).await.unwrap(); -/// # }; +/// # let _: Router = app; /// ``` #[must_use = "needs to be returned from a handler or otherwise turned into a Response to be useful"] #[derive(Debug, Clone)] diff --git a/axum/src/response/sse.rs b/axum/src/response/sse.rs index 80403607..2fdb8d9c 100644 --- a/axum/src/response/sse.rs +++ b/axum/src/response/sse.rs @@ -22,9 +22,7 @@ //! //! Sse::new(stream).keep_alive(KeepAlive::default()) //! } -//! # async { -//! # hyper::Server::bind(&"".parse().unwrap()).serve(app.into_make_service()).await.unwrap(); -//! # }; +//! # let _: Router = app; //! ``` use crate::{