use tower-http patch

This commit is contained in:
David Pedersen
2023-03-24 15:11:30 +01:00
parent c73b6a9969
commit 11a543a409
11 changed files with 25 additions and 46 deletions
+7
View File
@@ -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" }
+3 -3
View File
@@ -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 {}))
+5 -14
View File
@@ -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<Option<Result<Self::Data, Self::Error>>> {
/// # unimplemented!()
/// // ...
/// }
///
/// fn poll_trailers(
/// self: Pin<&mut Self>,
/// cx: &mut Context<'_>
/// ) -> Poll<Result<Option<HeaderMap>, Self::Error>> {
/// cx: &mut Context<'_>,
/// ) -> Poll<Option<Result<Frame<Self::Data>, Self::Error>>> {
/// # unimplemented!()
/// // ...
/// }
+1 -1
View File
@@ -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"]
+2 -7
View File
@@ -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
+1 -3
View File
@@ -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;
```
+1 -3
View File
@@ -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
+1 -3
View File
@@ -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
+2 -6
View File
@@ -308,16 +308,12 @@
//! ```toml
//! [dependencies]
//! axum = "<latest-version>"
//! hyper = { version = "<latest-version>", features = ["full"] }
//! tokio = { version = "<latest-version>", features = ["full"] }
//! tower = "<latest-version>"
//! ```
//!
//! 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.
+1 -3
View File
@@ -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)]
+1 -3
View File
@@ -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::{