diff --git a/axum/src/body/mod.rs b/axum/src/body/mod.rs index d5c5f661..c788207c 100644 --- a/axum/src/body/mod.rs +++ b/axum/src/body/mod.rs @@ -17,5 +17,5 @@ pub use bytes::Bytes; pub use axum_core::body::{boxed, BoxBody}; pub(crate) fn empty() -> BoxBody { - boxed(http_body::Empty::new()) + boxed(Empty::new()) } diff --git a/axum/src/body/stream_body.rs b/axum/src/body/stream_body.rs index bb3da56d..6c04ce81 100644 --- a/axum/src/body/stream_body.rs +++ b/axum/src/body/stream_body.rs @@ -1,15 +1,13 @@ use crate::{ - body, + body::{self, Bytes, HttpBody}, response::{IntoResponse, Response}, BoxError, Error, }; -use bytes::Bytes; use futures_util::{ ready, stream::{self, TryStream}, }; use http::HeaderMap; -use http_body::Body; use pin_project_lite::pin_project; use std::{ fmt, @@ -98,7 +96,7 @@ impl fmt::Debug for StreamBody { } } -impl Body for StreamBody +impl HttpBody for StreamBody where S: TryStream, S::Ok: Into, diff --git a/axum/src/docs/extract.md b/axum/src/docs/extract.md index 4d40f1dd..da62c5f8 100644 --- a/axum/src/docs/extract.md +++ b/axum/src/docs/extract.md @@ -413,7 +413,7 @@ use std::{ use tower_http::map_request_body::MapRequestBodyLayer; use axum::{ extract::{self, BodyStream}, - body::Body, + body::{Body, HttpBody}, routing::get, http::{header::HeaderMap, Request}, Router, @@ -421,9 +421,9 @@ use axum::{ struct MyBody(B); -impl http_body::Body for MyBody +impl HttpBody for MyBody where - B: http_body::Body + Unpin, + B: HttpBody + Unpin, { type Data = B::Data; type Error = B::Error; diff --git a/axum/src/extract/content_length_limit.rs b/axum/src/extract/content_length_limit.rs index a513094a..c1f2143c 100644 --- a/axum/src/extract/content_length_limit.rs +++ b/axum/src/extract/content_length_limit.rs @@ -80,8 +80,7 @@ impl Deref for ContentLengthLimit { #[cfg(test)] mod tests { use super::*; - use crate::{routing::post, test_helpers::*, Router}; - use bytes::Bytes; + use crate::{body::Bytes, routing::post, test_helpers::*, Router}; use http::StatusCode; use serde::Deserialize; @@ -127,7 +126,7 @@ mod tests { let res = client .post("/") .body(reqwest::Body::wrap_stream(futures_util::stream::iter( - vec![Ok::<_, std::io::Error>(bytes::Bytes::new())], + vec![Ok::<_, std::io::Error>(Bytes::new())], ))) .send() .await; diff --git a/axum/src/extract/extractor_middleware.rs b/axum/src/extract/extractor_middleware.rs index 2fd1f1fe..513d7677 100644 --- a/axum/src/extract/extractor_middleware.rs +++ b/axum/src/extract/extractor_middleware.rs @@ -4,10 +4,10 @@ use super::{FromRequest, RequestParts}; use crate::{ + body::{Bytes, HttpBody}, response::{IntoResponse, Response}, BoxError, }; -use bytes::Bytes; use futures_util::{future::BoxFuture, ready}; use http::Request; use pin_project_lite::pin_project; @@ -170,7 +170,7 @@ where E: FromRequest + 'static, ReqBody: Default + Send + 'static, S: Service, Response = Response> + Clone, - ResBody: http_body::Body + Send + 'static, + ResBody: HttpBody + Send + 'static, ResBody::Error: Into, { type Response = Response; @@ -229,7 +229,7 @@ where E: FromRequest, S: Service, Response = Response>, ReqBody: Default, - ResBody: http_body::Body + Send + 'static, + ResBody: HttpBody + Send + 'static, ResBody::Error: Into, { type Output = Result; diff --git a/axum/src/extract/form.rs b/axum/src/extract/form.rs index ed3b05cc..84d517df 100644 --- a/axum/src/extract/form.rs +++ b/axum/src/extract/form.rs @@ -1,4 +1,5 @@ use super::{has_content_type, rejection::*, FromRequest, RequestParts}; +use crate::body::{Bytes, HttpBody}; use crate::BoxError; use async_trait::async_trait; use http::Method; @@ -46,7 +47,7 @@ pub struct Form(pub T); impl FromRequest for Form where T: DeserializeOwned, - B: http_body::Body + Send, + B: HttpBody + Send, B::Data: Send, B::Error: Into, { @@ -63,7 +64,7 @@ where return Err(InvalidFormContentType.into()); } - let bytes = bytes::Bytes::from_request(req).await?; + let bytes = Bytes::from_request(req).await?; let value = serde_urlencoded::from_bytes(&bytes) .map_err(FailedToDeserializeQueryString::new::)?; @@ -83,6 +84,7 @@ impl Deref for Form { #[cfg(test)] mod tests { use super::*; + use crate::body::{Empty, Full}; use crate::extract::RequestParts; use http::Request; use serde::{Deserialize, Serialize}; @@ -98,7 +100,7 @@ mod tests { let mut req = RequestParts::new( Request::builder() .uri(uri.as_ref()) - .body(http_body::Empty::::new()) + .body(Empty::::new()) .unwrap(), ); assert_eq!(Form::::from_request(&mut req).await.unwrap().0, value); @@ -113,7 +115,7 @@ mod tests { http::header::CONTENT_TYPE, mime::APPLICATION_WWW_FORM_URLENCODED.as_ref(), ) - .body(http_body::Full::::new( + .body(Full::::new( serde_urlencoded::to_string(&value).unwrap().into(), )) .unwrap(), @@ -179,7 +181,7 @@ mod tests { .uri("http://example.com/test") .method(Method::POST) .header(http::header::CONTENT_TYPE, mime::APPLICATION_JSON.as_ref()) - .body(http_body::Full::::new( + .body(Full::::new( serde_urlencoded::to_string(&Pagination { size: Some(10), page: None, diff --git a/axum/src/extract/multipart.rs b/axum/src/extract/multipart.rs index 3cd6c692..c3366ee0 100644 --- a/axum/src/extract/multipart.rs +++ b/axum/src/extract/multipart.rs @@ -3,9 +3,9 @@ //! See [`Multipart`] for more details. use super::{rejection::*, BodyStream, FromRequest, RequestParts}; +use crate::body::{Bytes, HttpBody}; use crate::BoxError; use async_trait::async_trait; -use bytes::Bytes; use futures_util::stream::Stream; use http::header::{HeaderMap, CONTENT_TYPE}; use mime::Mime; @@ -52,7 +52,7 @@ pub struct Multipart { #[async_trait] impl FromRequest for Multipart where - B: http_body::Body + Default + Unpin + Send + 'static, + B: HttpBody + Default + Unpin + Send + 'static, B::Error: Into, { type Rejection = MultipartRejection; diff --git a/axum/src/extract/rejection.rs b/axum/src/extract/rejection.rs index 82ca9fda..2777a64f 100644 --- a/axum/src/extract/rejection.rs +++ b/axum/src/extract/rejection.rs @@ -1,11 +1,10 @@ //! Rejection response types. use crate::{ - body::boxed, + body::{boxed, Full}, response::{IntoResponse, Response}, BoxError, Error, }; -use http_body::Full; pub use crate::extract::path::FailedToDeserializePathParams; pub use axum_core::extract::rejection::*; diff --git a/axum/src/extract/request_parts.rs b/axum/src/extract/request_parts.rs index ce24f800..66e63d24 100644 --- a/axum/src/extract/request_parts.rs +++ b/axum/src/extract/request_parts.rs @@ -1,10 +1,11 @@ use super::{rejection::*, take_body, Extension, FromRequest, RequestParts}; -use crate::{body::Body, BoxError, Error}; +use crate::{ + body::{Body, Bytes, HttpBody}, + BoxError, Error, +}; use async_trait::async_trait; -use bytes::Bytes; use futures_util::stream::Stream; use http::Uri; -use http_body::Body as HttpBody; use std::{ convert::Infallible, fmt, @@ -93,7 +94,7 @@ where /// [`Stream`]: https://docs.rs/futures/latest/futures/stream/trait.Stream.html /// [`body::Body`]: crate::body::Body pub struct BodyStream( - SyncWrapper + Send + 'static>>>, + SyncWrapper + Send + 'static>>>, ); impl Stream for BodyStream { diff --git a/axum/src/extract/ws.rs b/axum/src/extract/ws.rs index a880e7c1..91250285 100644 --- a/axum/src/extract/ws.rs +++ b/axum/src/extract/ws.rs @@ -65,9 +65,12 @@ use self::rejection::*; use super::{rejection::*, FromRequest, RequestParts}; -use crate::{body, response::Response, Error}; +use crate::{ + body::{self, Bytes}, + response::Response, + Error, +}; use async_trait::async_trait; -use bytes::Bytes; use futures_util::{ sink::{Sink, SinkExt}, stream::{Stream, StreamExt}, diff --git a/axum/src/handler/mod.rs b/axum/src/handler/mod.rs index ff44c061..57a09444 100644 --- a/axum/src/handler/mod.rs +++ b/axum/src/handler/mod.rs @@ -5,7 +5,7 @@ //! Some examples of handlers: //! //! ```rust -//! use bytes::Bytes; +//! use axum::body::Bytes; //! use http::StatusCode; //! //! // Handler that immediately returns an empty `200 OK` response. @@ -71,7 +71,7 @@ //! [axum-debug]: https://docs.rs/axum-debug use crate::{ - body::{boxed, Body}, + body::{boxed, Body, Bytes, HttpBody}, extract::{ connect_info::{Connected, IntoMakeServiceWithConnectInfo}, FromRequest, RequestParts, @@ -81,7 +81,6 @@ use crate::{ BoxError, }; use async_trait::async_trait; -use bytes::Bytes; use http::Request; use std::{fmt, future::Future, marker::PhantomData}; use tower::ServiceExt; @@ -344,7 +343,7 @@ where S::Future: Send, T: 'static, ReqBody: Send + 'static, - ResBody: http_body::Body + Send + 'static, + ResBody: HttpBody + Send + 'static, ResBody::Error: Into, { type Sealed = sealed::Hidden; diff --git a/axum/src/json.rs b/axum/src/json.rs index 371be46f..32cf775c 100644 --- a/axum/src/json.rs +++ b/axum/src/json.rs @@ -1,5 +1,5 @@ use crate::{ - body, + body::{self, Bytes, Full, HttpBody}, extract::{rejection::*, FromRequest, RequestParts}, response::{IntoResponse, Response}, BoxError, @@ -9,7 +9,6 @@ use http::{ header::{self, HeaderValue}, StatusCode, }; -use http_body::Full; use serde::{de::DeserializeOwned, Serialize}; use std::ops::{Deref, DerefMut}; @@ -90,7 +89,7 @@ pub struct Json(pub T); impl FromRequest for Json where T: DeserializeOwned, - B: http_body::Body + Send, + B: HttpBody + Send, B::Data: Send, B::Error: Into, { @@ -98,7 +97,7 @@ where async fn from_request(req: &mut RequestParts) -> Result { if json_content_type(req)? { - let bytes = bytes::Bytes::from_request(req).await?; + let bytes = Bytes::from_request(req).await?; let value = serde_json::from_slice(&bytes).map_err(InvalidJsonBody::from_err)?; diff --git a/axum/src/macros.rs b/axum/src/macros.rs index 26748f3a..9e8fd3b2 100644 --- a/axum/src/macros.rs +++ b/axum/src/macros.rs @@ -60,7 +60,7 @@ macro_rules! define_rejection { #[allow(deprecated)] impl $crate::response::IntoResponse for $name { fn into_response(self) -> $crate::response::Response { - let mut res = http::Response::new($crate::body::boxed(http_body::Full::from($body))); + let mut res = http::Response::new($crate::body::boxed(crate::body::Full::from($body))); *res.status_mut() = http::StatusCode::$status; res } @@ -103,7 +103,7 @@ macro_rules! define_rejection { impl IntoResponse for $name { fn into_response(self) -> $crate::response::Response { let mut res = - http::Response::new($crate::body::boxed(http_body::Full::from(format!(concat!($body, ": {}"), self.0)))); + http::Response::new($crate::body::boxed(crate::body::Full::from(format!(concat!($body, ": {}"), self.0)))); *res.status_mut() = http::StatusCode::$status; res } diff --git a/axum/src/response/mod.rs b/axum/src/response/mod.rs index 3682b40d..fd8f2b8b 100644 --- a/axum/src/response/mod.rs +++ b/axum/src/response/mod.rs @@ -1,9 +1,8 @@ #![doc = include_str!("../docs/response.md")] +use crate::body::{Bytes, Full}; use axum_core::body::boxed; -use bytes::Bytes; use http::{header, HeaderValue}; -use http_body::Full; mod redirect; @@ -48,11 +47,11 @@ impl From for Html { #[cfg(test)] mod tests { use super::*; + use crate::body::Empty; use http::{ header::{HeaderMap, HeaderName}, StatusCode, }; - use http_body::Empty; #[test] fn test_merge_headers() { diff --git a/axum/src/response/redirect.rs b/axum/src/response/redirect.rs index 2ba7bfb7..482e4606 100644 --- a/axum/src/response/redirect.rs +++ b/axum/src/response/redirect.rs @@ -1,7 +1,6 @@ use super::{IntoResponse, Response}; -use crate::body::boxed; +use crate::body::{boxed, Empty}; use http::{header::LOCATION, HeaderValue, StatusCode, Uri}; -use http_body::Empty; use std::convert::TryFrom; /// Response that redirects the request to another location. diff --git a/axum/src/response/sse.rs b/axum/src/response/sse.rs index 8fa77f13..fbf92d88 100644 --- a/axum/src/response/sse.rs +++ b/axum/src/response/sse.rs @@ -28,16 +28,14 @@ //! ``` use crate::{ - body, + body::{self, Bytes, HttpBody}, response::{IntoResponse, Response}, BoxError, }; -use bytes::Bytes; use futures_util::{ ready, stream::{Stream, TryStream}, }; -use http_body::Body as HttpBody; use pin_project_lite::pin_project; use std::{ borrow::Cow, diff --git a/axum/src/routing/method_routing.rs b/axum/src/routing/method_routing.rs index a556d30a..e151de66 100644 --- a/axum/src/routing/method_routing.rs +++ b/axum/src/routing/method_routing.rs @@ -1,5 +1,5 @@ use crate::{ - body::{boxed, Body, Bytes}, + body::{boxed, Body, Bytes, Empty, HttpBody}, error_handling::{HandleError, HandleErrorLayer}, handler::Handler, http::{Method, Request, StatusCode}, @@ -7,7 +7,6 @@ use crate::{ routing::{Fallback, MethodFilter, Route}, BoxError, }; -use http_body::Empty; use std::{ convert::Infallible, fmt, @@ -78,7 +77,7 @@ macro_rules! top_level_service_fn { where S: Service, Response = Response> + Clone + Send + 'static, S::Future: Send + 'static, - ResBody: http_body::Body + Send + 'static, + ResBody: HttpBody + Send + 'static, ResBody::Error: Into, { on_service(MethodFilter::$method, svc) @@ -213,7 +212,7 @@ macro_rules! chained_service_fn { + Send + 'static, S::Future: Send + 'static, - ResBody: http_body::Body + Send + 'static, + ResBody: HttpBody + Send + 'static, ResBody::Error: Into, { self.on_service(MethodFilter::$method, svc) @@ -321,7 +320,7 @@ pub fn on_service( where S: Service, Response = Response> + Clone + Send + 'static, S::Future: Send + 'static, - ResBody: http_body::Body + Send + 'static, + ResBody: HttpBody + Send + 'static, ResBody::Error: Into, { MethodRouter::new().on_service(filter, svc) @@ -384,7 +383,7 @@ pub fn any_service(svc: S) -> MethodRouter, Response = Response> + Clone + Send + 'static, S::Future: Send + 'static, - ResBody: http_body::Body + Send + 'static, + ResBody: HttpBody + Send + 'static, ResBody::Error: Into, { MethodRouter::new().fallback(svc) @@ -607,7 +606,7 @@ impl MethodRouter { + Send + 'static, S::Future: Send + 'static, - ResBody: http_body::Body + Send + 'static, + ResBody: HttpBody + Send + 'static, ResBody::Error: Into, { self.on_service_boxed_response_body(filter, svc.map_response(|res| res.map(boxed))) @@ -630,7 +629,7 @@ impl MethodRouter { + Send + 'static, S::Future: Send + 'static, - ResBody: http_body::Body + Send + 'static, + ResBody: HttpBody + Send + 'static, ResBody::Error: Into, { self.fallback = Fallback::Custom(Route::new(svc.map_response(|res| res.map(boxed)))); @@ -658,7 +657,7 @@ impl MethodRouter { + Send + 'static, >>::Future: Send + 'static, - NewResBody: http_body::Body + Send + 'static, + NewResBody: HttpBody + Send + 'static, NewResBody::Error: Into, { let layer = ServiceBuilder::new() @@ -691,7 +690,7 @@ impl MethodRouter { + Send + 'static, >>::Future: Send + 'static, - NewResBody: http_body::Body + Send + 'static, + NewResBody: HttpBody + Send + 'static, NewResBody::Error: Into, { let layer = ServiceBuilder::new() diff --git a/axum/src/routing/mod.rs b/axum/src/routing/mod.rs index f0bda4a4..7eac8c66 100644 --- a/axum/src/routing/mod.rs +++ b/axum/src/routing/mod.rs @@ -2,7 +2,7 @@ use self::{future::RouterFuture, not_found::NotFound}; use crate::{ - body::{boxed, Body}, + body::{boxed, Body, Bytes, HttpBody}, extract::{ connect_info::{Connected, IntoMakeServiceWithConnectInfo}, MatchedPath, OriginalUri, @@ -12,7 +12,6 @@ use crate::{ util::{try_downcast, ByteStr, PercentDecodedByteStr}, BoxError, }; -use bytes::Bytes; use http::{Request, StatusCode, Uri}; use std::{ borrow::Cow, @@ -278,7 +277,7 @@ where + Send + 'static, >>::Future: Send + 'static, - NewResBody: http_body::Body + Send + 'static, + NewResBody: HttpBody + Send + 'static, NewResBody::Error: Into, { let layer = ServiceBuilder::new() @@ -319,7 +318,7 @@ where + Send + 'static, >>::Future: Send + 'static, - NewResBody: http_body::Body + Send + 'static, + NewResBody: HttpBody + Send + 'static, NewResBody::Error: Into, { let layer = ServiceBuilder::new() diff --git a/axum/src/routing/route.rs b/axum/src/routing/route.rs index 3c6fab1d..b5a9a74c 100644 --- a/axum/src/routing/route.rs +++ b/axum/src/routing/route.rs @@ -1,9 +1,8 @@ use crate::{ - body::{boxed, Body}, + body::{boxed, Body, Empty}, response::Response, }; use http::Request; -use http_body::Empty; use pin_project_lite::pin_project; use std::{ convert::Infallible, diff --git a/axum/src/routing/tests/merge.rs b/axum/src/routing/tests/merge.rs index 11756fbb..58af0151 100644 --- a/axum/src/routing/tests/merge.rs +++ b/axum/src/routing/tests/merge.rs @@ -1,5 +1,8 @@ use super::*; -use crate::{error_handling::HandleErrorLayer, extract::OriginalUri, response::IntoResponse, Json}; +use crate::{ + body::HttpBody, error_handling::HandleErrorLayer, extract::OriginalUri, response::IntoResponse, + Json, +}; use serde_json::{json, Value}; use tower::{limit::ConcurrencyLimitLayer, timeout::TimeoutLayer}; @@ -62,7 +65,7 @@ async fn multiple_ors_balanced_differently() { async fn test(name: &str, app: S) where S: Service, Response = Response> + Clone + Send + 'static, - ResBody: http_body::Body + Send + 'static, + ResBody: HttpBody + Send + 'static, ResBody::Data: Send, ResBody::Error: Into, S::Future: Send, diff --git a/axum/src/routing/tests/mod.rs b/axum/src/routing/tests/mod.rs index ecdd0ab8..67e7f06e 100644 --- a/axum/src/routing/tests/mod.rs +++ b/axum/src/routing/tests/mod.rs @@ -1,4 +1,5 @@ use crate::{ + body::{Bytes, Empty}, error_handling::HandleErrorLayer, extract::{self, Path}, handler::Handler, @@ -7,7 +8,6 @@ use crate::{ test_helpers::*, BoxError, Json, Router, }; -use bytes::Bytes; use http::{Method, Request, Response, StatusCode, Uri}; use hyper::Body; use serde::Deserialize; @@ -234,7 +234,7 @@ async fn wrong_method_service() { struct Svc; impl Service for Svc { - type Response = Response>; + type Response = Response>; type Error = Infallible; type Future = Ready>; @@ -243,7 +243,7 @@ async fn wrong_method_service() { } fn call(&mut self, _req: R) -> Self::Future { - ready(Ok(Response::new(http_body::Empty::new()))) + ready(Ok(Response::new(Empty::new()))) } } diff --git a/axum/src/test_helpers.rs b/axum/src/test_helpers.rs index 992305d7..fef2f08b 100644 --- a/axum/src/test_helpers.rs +++ b/axum/src/test_helpers.rs @@ -1,5 +1,6 @@ #![allow(clippy::blacklisted_name)] +use crate::body::HttpBody; use crate::BoxError; use http::{ header::{HeaderName, HeaderValue}, @@ -28,7 +29,7 @@ impl TestClient { pub(crate) fn new(svc: S) -> Self where S: Service, Response = http::Response> + Clone + Send + 'static, - ResBody: http_body::Body + Send + 'static, + ResBody: HttpBody + Send + 'static, ResBody::Data: Send, ResBody::Error: Into, S::Future: Send, diff --git a/axum/src/util.rs b/axum/src/util.rs index 34e7b761..9cb96c4a 100644 --- a/axum/src/util.rs +++ b/axum/src/util.rs @@ -1,4 +1,4 @@ -use bytes::Bytes; +use crate::body::Bytes; use pin_project_lite::pin_project; use std::fmt; use std::ops::Deref;