Use HttpBody type alias internally (#624)

* use 'crate::body::HttpBody' instead of 'http_body::Body'

* use 'crate::body::Bytes' instead of 'bytes::Bytes'

* rustfmt

* fix warning

* Update axum/src/routing/method_routing.rs

Co-authored-by: David Pedersen <david.pdrsn@gmail.com>

* Update axum/src/routing/method_routing.rs

Co-authored-by: David Pedersen <david.pdrsn@gmail.com>

Co-authored-by: David Pedersen <david.pdrsn@gmail.com>
This commit is contained in:
lz1998 2021-12-14 19:58:45 +08:00 committed by GitHub
parent 4625e1953b
commit dea36db400
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 67 additions and 70 deletions

View File

@ -17,5 +17,5 @@ pub use bytes::Bytes;
pub use axum_core::body::{boxed, BoxBody}; pub use axum_core::body::{boxed, BoxBody};
pub(crate) fn empty() -> BoxBody { pub(crate) fn empty() -> BoxBody {
boxed(http_body::Empty::new()) boxed(Empty::new())
} }

View File

@ -1,15 +1,13 @@
use crate::{ use crate::{
body, body::{self, Bytes, HttpBody},
response::{IntoResponse, Response}, response::{IntoResponse, Response},
BoxError, Error, BoxError, Error,
}; };
use bytes::Bytes;
use futures_util::{ use futures_util::{
ready, ready,
stream::{self, TryStream}, stream::{self, TryStream},
}; };
use http::HeaderMap; use http::HeaderMap;
use http_body::Body;
use pin_project_lite::pin_project; use pin_project_lite::pin_project;
use std::{ use std::{
fmt, fmt,
@ -98,7 +96,7 @@ impl<S> fmt::Debug for StreamBody<S> {
} }
} }
impl<S> Body for StreamBody<S> impl<S> HttpBody for StreamBody<S>
where where
S: TryStream, S: TryStream,
S::Ok: Into<Bytes>, S::Ok: Into<Bytes>,

View File

@ -413,7 +413,7 @@ use std::{
use tower_http::map_request_body::MapRequestBodyLayer; use tower_http::map_request_body::MapRequestBodyLayer;
use axum::{ use axum::{
extract::{self, BodyStream}, extract::{self, BodyStream},
body::Body, body::{Body, HttpBody},
routing::get, routing::get,
http::{header::HeaderMap, Request}, http::{header::HeaderMap, Request},
Router, Router,
@ -421,9 +421,9 @@ use axum::{
struct MyBody<B>(B); struct MyBody<B>(B);
impl<B> http_body::Body for MyBody<B> impl<B> HttpBody for MyBody<B>
where where
B: http_body::Body + Unpin, B: HttpBody + Unpin,
{ {
type Data = B::Data; type Data = B::Data;
type Error = B::Error; type Error = B::Error;

View File

@ -80,8 +80,7 @@ impl<T, const N: u64> Deref for ContentLengthLimit<T, N> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::{routing::post, test_helpers::*, Router}; use crate::{body::Bytes, routing::post, test_helpers::*, Router};
use bytes::Bytes;
use http::StatusCode; use http::StatusCode;
use serde::Deserialize; use serde::Deserialize;
@ -127,7 +126,7 @@ mod tests {
let res = client let res = client
.post("/") .post("/")
.body(reqwest::Body::wrap_stream(futures_util::stream::iter( .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() .send()
.await; .await;

View File

@ -4,10 +4,10 @@
use super::{FromRequest, RequestParts}; use super::{FromRequest, RequestParts};
use crate::{ use crate::{
body::{Bytes, HttpBody},
response::{IntoResponse, Response}, response::{IntoResponse, Response},
BoxError, BoxError,
}; };
use bytes::Bytes;
use futures_util::{future::BoxFuture, ready}; use futures_util::{future::BoxFuture, ready};
use http::Request; use http::Request;
use pin_project_lite::pin_project; use pin_project_lite::pin_project;
@ -170,7 +170,7 @@ where
E: FromRequest<ReqBody> + 'static, E: FromRequest<ReqBody> + 'static,
ReqBody: Default + Send + 'static, ReqBody: Default + Send + 'static,
S: Service<Request<ReqBody>, Response = Response<ResBody>> + Clone, S: Service<Request<ReqBody>, Response = Response<ResBody>> + Clone,
ResBody: http_body::Body<Data = Bytes> + Send + 'static, ResBody: HttpBody<Data = Bytes> + Send + 'static,
ResBody::Error: Into<BoxError>, ResBody::Error: Into<BoxError>,
{ {
type Response = Response; type Response = Response;
@ -229,7 +229,7 @@ where
E: FromRequest<ReqBody>, E: FromRequest<ReqBody>,
S: Service<Request<ReqBody>, Response = Response<ResBody>>, S: Service<Request<ReqBody>, Response = Response<ResBody>>,
ReqBody: Default, ReqBody: Default,
ResBody: http_body::Body<Data = Bytes> + Send + 'static, ResBody: HttpBody<Data = Bytes> + Send + 'static,
ResBody::Error: Into<BoxError>, ResBody::Error: Into<BoxError>,
{ {
type Output = Result<Response, S::Error>; type Output = Result<Response, S::Error>;

View File

@ -1,4 +1,5 @@
use super::{has_content_type, rejection::*, FromRequest, RequestParts}; use super::{has_content_type, rejection::*, FromRequest, RequestParts};
use crate::body::{Bytes, HttpBody};
use crate::BoxError; use crate::BoxError;
use async_trait::async_trait; use async_trait::async_trait;
use http::Method; use http::Method;
@ -46,7 +47,7 @@ pub struct Form<T>(pub T);
impl<T, B> FromRequest<B> for Form<T> impl<T, B> FromRequest<B> for Form<T>
where where
T: DeserializeOwned, T: DeserializeOwned,
B: http_body::Body + Send, B: HttpBody + Send,
B::Data: Send, B::Data: Send,
B::Error: Into<BoxError>, B::Error: Into<BoxError>,
{ {
@ -63,7 +64,7 @@ where
return Err(InvalidFormContentType.into()); 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) let value = serde_urlencoded::from_bytes(&bytes)
.map_err(FailedToDeserializeQueryString::new::<T, _>)?; .map_err(FailedToDeserializeQueryString::new::<T, _>)?;
@ -83,6 +84,7 @@ impl<T> Deref for Form<T> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::body::{Empty, Full};
use crate::extract::RequestParts; use crate::extract::RequestParts;
use http::Request; use http::Request;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -98,7 +100,7 @@ mod tests {
let mut req = RequestParts::new( let mut req = RequestParts::new(
Request::builder() Request::builder()
.uri(uri.as_ref()) .uri(uri.as_ref())
.body(http_body::Empty::<bytes::Bytes>::new()) .body(Empty::<Bytes>::new())
.unwrap(), .unwrap(),
); );
assert_eq!(Form::<T>::from_request(&mut req).await.unwrap().0, value); assert_eq!(Form::<T>::from_request(&mut req).await.unwrap().0, value);
@ -113,7 +115,7 @@ mod tests {
http::header::CONTENT_TYPE, http::header::CONTENT_TYPE,
mime::APPLICATION_WWW_FORM_URLENCODED.as_ref(), mime::APPLICATION_WWW_FORM_URLENCODED.as_ref(),
) )
.body(http_body::Full::<bytes::Bytes>::new( .body(Full::<Bytes>::new(
serde_urlencoded::to_string(&value).unwrap().into(), serde_urlencoded::to_string(&value).unwrap().into(),
)) ))
.unwrap(), .unwrap(),
@ -179,7 +181,7 @@ mod tests {
.uri("http://example.com/test") .uri("http://example.com/test")
.method(Method::POST) .method(Method::POST)
.header(http::header::CONTENT_TYPE, mime::APPLICATION_JSON.as_ref()) .header(http::header::CONTENT_TYPE, mime::APPLICATION_JSON.as_ref())
.body(http_body::Full::<bytes::Bytes>::new( .body(Full::<Bytes>::new(
serde_urlencoded::to_string(&Pagination { serde_urlencoded::to_string(&Pagination {
size: Some(10), size: Some(10),
page: None, page: None,

View File

@ -3,9 +3,9 @@
//! See [`Multipart`] for more details. //! See [`Multipart`] for more details.
use super::{rejection::*, BodyStream, FromRequest, RequestParts}; use super::{rejection::*, BodyStream, FromRequest, RequestParts};
use crate::body::{Bytes, HttpBody};
use crate::BoxError; use crate::BoxError;
use async_trait::async_trait; use async_trait::async_trait;
use bytes::Bytes;
use futures_util::stream::Stream; use futures_util::stream::Stream;
use http::header::{HeaderMap, CONTENT_TYPE}; use http::header::{HeaderMap, CONTENT_TYPE};
use mime::Mime; use mime::Mime;
@ -52,7 +52,7 @@ pub struct Multipart {
#[async_trait] #[async_trait]
impl<B> FromRequest<B> for Multipart impl<B> FromRequest<B> for Multipart
where where
B: http_body::Body<Data = Bytes> + Default + Unpin + Send + 'static, B: HttpBody<Data = Bytes> + Default + Unpin + Send + 'static,
B::Error: Into<BoxError>, B::Error: Into<BoxError>,
{ {
type Rejection = MultipartRejection; type Rejection = MultipartRejection;

View File

@ -1,11 +1,10 @@
//! Rejection response types. //! Rejection response types.
use crate::{ use crate::{
body::boxed, body::{boxed, Full},
response::{IntoResponse, Response}, response::{IntoResponse, Response},
BoxError, Error, BoxError, Error,
}; };
use http_body::Full;
pub use crate::extract::path::FailedToDeserializePathParams; pub use crate::extract::path::FailedToDeserializePathParams;
pub use axum_core::extract::rejection::*; pub use axum_core::extract::rejection::*;

View File

@ -1,10 +1,11 @@
use super::{rejection::*, take_body, Extension, FromRequest, RequestParts}; 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 async_trait::async_trait;
use bytes::Bytes;
use futures_util::stream::Stream; use futures_util::stream::Stream;
use http::Uri; use http::Uri;
use http_body::Body as HttpBody;
use std::{ use std::{
convert::Infallible, convert::Infallible,
fmt, fmt,
@ -93,7 +94,7 @@ where
/// [`Stream`]: https://docs.rs/futures/latest/futures/stream/trait.Stream.html /// [`Stream`]: https://docs.rs/futures/latest/futures/stream/trait.Stream.html
/// [`body::Body`]: crate::body::Body /// [`body::Body`]: crate::body::Body
pub struct BodyStream( pub struct BodyStream(
SyncWrapper<Pin<Box<dyn http_body::Body<Data = Bytes, Error = Error> + Send + 'static>>>, SyncWrapper<Pin<Box<dyn HttpBody<Data = Bytes, Error = Error> + Send + 'static>>>,
); );
impl Stream for BodyStream { impl Stream for BodyStream {

View File

@ -65,9 +65,12 @@
use self::rejection::*; use self::rejection::*;
use super::{rejection::*, FromRequest, RequestParts}; 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 async_trait::async_trait;
use bytes::Bytes;
use futures_util::{ use futures_util::{
sink::{Sink, SinkExt}, sink::{Sink, SinkExt},
stream::{Stream, StreamExt}, stream::{Stream, StreamExt},

View File

@ -5,7 +5,7 @@
//! Some examples of handlers: //! Some examples of handlers:
//! //!
//! ```rust //! ```rust
//! use bytes::Bytes; //! use axum::body::Bytes;
//! use http::StatusCode; //! use http::StatusCode;
//! //!
//! // Handler that immediately returns an empty `200 OK` response. //! // Handler that immediately returns an empty `200 OK` response.
@ -71,7 +71,7 @@
//! [axum-debug]: https://docs.rs/axum-debug //! [axum-debug]: https://docs.rs/axum-debug
use crate::{ use crate::{
body::{boxed, Body}, body::{boxed, Body, Bytes, HttpBody},
extract::{ extract::{
connect_info::{Connected, IntoMakeServiceWithConnectInfo}, connect_info::{Connected, IntoMakeServiceWithConnectInfo},
FromRequest, RequestParts, FromRequest, RequestParts,
@ -81,7 +81,6 @@ use crate::{
BoxError, BoxError,
}; };
use async_trait::async_trait; use async_trait::async_trait;
use bytes::Bytes;
use http::Request; use http::Request;
use std::{fmt, future::Future, marker::PhantomData}; use std::{fmt, future::Future, marker::PhantomData};
use tower::ServiceExt; use tower::ServiceExt;
@ -344,7 +343,7 @@ where
S::Future: Send, S::Future: Send,
T: 'static, T: 'static,
ReqBody: Send + 'static, ReqBody: Send + 'static,
ResBody: http_body::Body<Data = Bytes> + Send + 'static, ResBody: HttpBody<Data = Bytes> + Send + 'static,
ResBody::Error: Into<BoxError>, ResBody::Error: Into<BoxError>,
{ {
type Sealed = sealed::Hidden; type Sealed = sealed::Hidden;

View File

@ -1,5 +1,5 @@
use crate::{ use crate::{
body, body::{self, Bytes, Full, HttpBody},
extract::{rejection::*, FromRequest, RequestParts}, extract::{rejection::*, FromRequest, RequestParts},
response::{IntoResponse, Response}, response::{IntoResponse, Response},
BoxError, BoxError,
@ -9,7 +9,6 @@ use http::{
header::{self, HeaderValue}, header::{self, HeaderValue},
StatusCode, StatusCode,
}; };
use http_body::Full;
use serde::{de::DeserializeOwned, Serialize}; use serde::{de::DeserializeOwned, Serialize};
use std::ops::{Deref, DerefMut}; use std::ops::{Deref, DerefMut};
@ -90,7 +89,7 @@ pub struct Json<T>(pub T);
impl<T, B> FromRequest<B> for Json<T> impl<T, B> FromRequest<B> for Json<T>
where where
T: DeserializeOwned, T: DeserializeOwned,
B: http_body::Body + Send, B: HttpBody + Send,
B::Data: Send, B::Data: Send,
B::Error: Into<BoxError>, B::Error: Into<BoxError>,
{ {
@ -98,7 +97,7 @@ where
async fn from_request(req: &mut RequestParts<B>) -> Result<Self, Self::Rejection> { async fn from_request(req: &mut RequestParts<B>) -> Result<Self, Self::Rejection> {
if json_content_type(req)? { 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)?; let value = serde_json::from_slice(&bytes).map_err(InvalidJsonBody::from_err)?;

View File

@ -60,7 +60,7 @@ macro_rules! define_rejection {
#[allow(deprecated)] #[allow(deprecated)]
impl $crate::response::IntoResponse for $name { impl $crate::response::IntoResponse for $name {
fn into_response(self) -> $crate::response::Response { 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.status_mut() = http::StatusCode::$status;
res res
} }
@ -103,7 +103,7 @@ macro_rules! define_rejection {
impl IntoResponse for $name { impl IntoResponse for $name {
fn into_response(self) -> $crate::response::Response { fn into_response(self) -> $crate::response::Response {
let mut res = 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.status_mut() = http::StatusCode::$status;
res res
} }

View File

@ -1,9 +1,8 @@
#![doc = include_str!("../docs/response.md")] #![doc = include_str!("../docs/response.md")]
use crate::body::{Bytes, Full};
use axum_core::body::boxed; use axum_core::body::boxed;
use bytes::Bytes;
use http::{header, HeaderValue}; use http::{header, HeaderValue};
use http_body::Full;
mod redirect; mod redirect;
@ -48,11 +47,11 @@ impl<T> From<T> for Html<T> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::body::Empty;
use http::{ use http::{
header::{HeaderMap, HeaderName}, header::{HeaderMap, HeaderName},
StatusCode, StatusCode,
}; };
use http_body::Empty;
#[test] #[test]
fn test_merge_headers() { fn test_merge_headers() {

View File

@ -1,7 +1,6 @@
use super::{IntoResponse, Response}; use super::{IntoResponse, Response};
use crate::body::boxed; use crate::body::{boxed, Empty};
use http::{header::LOCATION, HeaderValue, StatusCode, Uri}; use http::{header::LOCATION, HeaderValue, StatusCode, Uri};
use http_body::Empty;
use std::convert::TryFrom; use std::convert::TryFrom;
/// Response that redirects the request to another location. /// Response that redirects the request to another location.

View File

@ -28,16 +28,14 @@
//! ``` //! ```
use crate::{ use crate::{
body, body::{self, Bytes, HttpBody},
response::{IntoResponse, Response}, response::{IntoResponse, Response},
BoxError, BoxError,
}; };
use bytes::Bytes;
use futures_util::{ use futures_util::{
ready, ready,
stream::{Stream, TryStream}, stream::{Stream, TryStream},
}; };
use http_body::Body as HttpBody;
use pin_project_lite::pin_project; use pin_project_lite::pin_project;
use std::{ use std::{
borrow::Cow, borrow::Cow,

View File

@ -1,5 +1,5 @@
use crate::{ use crate::{
body::{boxed, Body, Bytes}, body::{boxed, Body, Bytes, Empty, HttpBody},
error_handling::{HandleError, HandleErrorLayer}, error_handling::{HandleError, HandleErrorLayer},
handler::Handler, handler::Handler,
http::{Method, Request, StatusCode}, http::{Method, Request, StatusCode},
@ -7,7 +7,6 @@ use crate::{
routing::{Fallback, MethodFilter, Route}, routing::{Fallback, MethodFilter, Route},
BoxError, BoxError,
}; };
use http_body::Empty;
use std::{ use std::{
convert::Infallible, convert::Infallible,
fmt, fmt,
@ -78,7 +77,7 @@ macro_rules! top_level_service_fn {
where where
S: Service<Request<ReqBody>, Response = Response<ResBody>> + Clone + Send + 'static, S: Service<Request<ReqBody>, Response = Response<ResBody>> + Clone + Send + 'static,
S::Future: Send + 'static, S::Future: Send + 'static,
ResBody: http_body::Body<Data = Bytes> + Send + 'static, ResBody: HttpBody<Data = Bytes> + Send + 'static,
ResBody::Error: Into<BoxError>, ResBody::Error: Into<BoxError>,
{ {
on_service(MethodFilter::$method, svc) on_service(MethodFilter::$method, svc)
@ -213,7 +212,7 @@ macro_rules! chained_service_fn {
+ Send + Send
+ 'static, + 'static,
S::Future: Send + 'static, S::Future: Send + 'static,
ResBody: http_body::Body<Data = Bytes> + Send + 'static, ResBody: HttpBody<Data = Bytes> + Send + 'static,
ResBody::Error: Into<BoxError>, ResBody::Error: Into<BoxError>,
{ {
self.on_service(MethodFilter::$method, svc) self.on_service(MethodFilter::$method, svc)
@ -321,7 +320,7 @@ pub fn on_service<S, ReqBody, ResBody>(
where where
S: Service<Request<ReqBody>, Response = Response<ResBody>> + Clone + Send + 'static, S: Service<Request<ReqBody>, Response = Response<ResBody>> + Clone + Send + 'static,
S::Future: Send + 'static, S::Future: Send + 'static,
ResBody: http_body::Body<Data = Bytes> + Send + 'static, ResBody: HttpBody<Data = Bytes> + Send + 'static,
ResBody::Error: Into<BoxError>, ResBody::Error: Into<BoxError>,
{ {
MethodRouter::new().on_service(filter, svc) MethodRouter::new().on_service(filter, svc)
@ -384,7 +383,7 @@ pub fn any_service<S, ReqBody, ResBody>(svc: S) -> MethodRouter<ReqBody, S::Erro
where where
S: Service<Request<ReqBody>, Response = Response<ResBody>> + Clone + Send + 'static, S: Service<Request<ReqBody>, Response = Response<ResBody>> + Clone + Send + 'static,
S::Future: Send + 'static, S::Future: Send + 'static,
ResBody: http_body::Body<Data = Bytes> + Send + 'static, ResBody: HttpBody<Data = Bytes> + Send + 'static,
ResBody::Error: Into<BoxError>, ResBody::Error: Into<BoxError>,
{ {
MethodRouter::new().fallback(svc) MethodRouter::new().fallback(svc)
@ -607,7 +606,7 @@ impl<ReqBody, E> MethodRouter<ReqBody, E> {
+ Send + Send
+ 'static, + 'static,
S::Future: Send + 'static, S::Future: Send + 'static,
ResBody: http_body::Body<Data = Bytes> + Send + 'static, ResBody: HttpBody<Data = Bytes> + Send + 'static,
ResBody::Error: Into<BoxError>, ResBody::Error: Into<BoxError>,
{ {
self.on_service_boxed_response_body(filter, svc.map_response(|res| res.map(boxed))) self.on_service_boxed_response_body(filter, svc.map_response(|res| res.map(boxed)))
@ -630,7 +629,7 @@ impl<ReqBody, E> MethodRouter<ReqBody, E> {
+ Send + Send
+ 'static, + 'static,
S::Future: Send + 'static, S::Future: Send + 'static,
ResBody: http_body::Body<Data = Bytes> + Send + 'static, ResBody: HttpBody<Data = Bytes> + Send + 'static,
ResBody::Error: Into<BoxError>, ResBody::Error: Into<BoxError>,
{ {
self.fallback = Fallback::Custom(Route::new(svc.map_response(|res| res.map(boxed)))); self.fallback = Fallback::Custom(Route::new(svc.map_response(|res| res.map(boxed))));
@ -658,7 +657,7 @@ impl<ReqBody, E> MethodRouter<ReqBody, E> {
+ Send + Send
+ 'static, + 'static,
<L::Service as Service<Request<NewReqBody>>>::Future: Send + 'static, <L::Service as Service<Request<NewReqBody>>>::Future: Send + 'static,
NewResBody: http_body::Body<Data = Bytes> + Send + 'static, NewResBody: HttpBody<Data = Bytes> + Send + 'static,
NewResBody::Error: Into<BoxError>, NewResBody::Error: Into<BoxError>,
{ {
let layer = ServiceBuilder::new() let layer = ServiceBuilder::new()
@ -691,7 +690,7 @@ impl<ReqBody, E> MethodRouter<ReqBody, E> {
+ Send + Send
+ 'static, + 'static,
<L::Service as Service<Request<ReqBody>>>::Future: Send + 'static, <L::Service as Service<Request<ReqBody>>>::Future: Send + 'static,
NewResBody: http_body::Body<Data = Bytes> + Send + 'static, NewResBody: HttpBody<Data = Bytes> + Send + 'static,
NewResBody::Error: Into<BoxError>, NewResBody::Error: Into<BoxError>,
{ {
let layer = ServiceBuilder::new() let layer = ServiceBuilder::new()

View File

@ -2,7 +2,7 @@
use self::{future::RouterFuture, not_found::NotFound}; use self::{future::RouterFuture, not_found::NotFound};
use crate::{ use crate::{
body::{boxed, Body}, body::{boxed, Body, Bytes, HttpBody},
extract::{ extract::{
connect_info::{Connected, IntoMakeServiceWithConnectInfo}, connect_info::{Connected, IntoMakeServiceWithConnectInfo},
MatchedPath, OriginalUri, MatchedPath, OriginalUri,
@ -12,7 +12,6 @@ use crate::{
util::{try_downcast, ByteStr, PercentDecodedByteStr}, util::{try_downcast, ByteStr, PercentDecodedByteStr},
BoxError, BoxError,
}; };
use bytes::Bytes;
use http::{Request, StatusCode, Uri}; use http::{Request, StatusCode, Uri};
use std::{ use std::{
borrow::Cow, borrow::Cow,
@ -278,7 +277,7 @@ where
+ Send + Send
+ 'static, + 'static,
<L::Service as Service<Request<NewReqBody>>>::Future: Send + 'static, <L::Service as Service<Request<NewReqBody>>>::Future: Send + 'static,
NewResBody: http_body::Body<Data = Bytes> + Send + 'static, NewResBody: HttpBody<Data = Bytes> + Send + 'static,
NewResBody::Error: Into<BoxError>, NewResBody::Error: Into<BoxError>,
{ {
let layer = ServiceBuilder::new() let layer = ServiceBuilder::new()
@ -319,7 +318,7 @@ where
+ Send + Send
+ 'static, + 'static,
<L::Service as Service<Request<B>>>::Future: Send + 'static, <L::Service as Service<Request<B>>>::Future: Send + 'static,
NewResBody: http_body::Body<Data = Bytes> + Send + 'static, NewResBody: HttpBody<Data = Bytes> + Send + 'static,
NewResBody::Error: Into<BoxError>, NewResBody::Error: Into<BoxError>,
{ {
let layer = ServiceBuilder::new() let layer = ServiceBuilder::new()

View File

@ -1,9 +1,8 @@
use crate::{ use crate::{
body::{boxed, Body}, body::{boxed, Body, Empty},
response::Response, response::Response,
}; };
use http::Request; use http::Request;
use http_body::Empty;
use pin_project_lite::pin_project; use pin_project_lite::pin_project;
use std::{ use std::{
convert::Infallible, convert::Infallible,

View File

@ -1,5 +1,8 @@
use super::*; 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 serde_json::{json, Value};
use tower::{limit::ConcurrencyLimitLayer, timeout::TimeoutLayer}; use tower::{limit::ConcurrencyLimitLayer, timeout::TimeoutLayer};
@ -62,7 +65,7 @@ async fn multiple_ors_balanced_differently() {
async fn test<S, ResBody>(name: &str, app: S) async fn test<S, ResBody>(name: &str, app: S)
where where
S: Service<Request<Body>, Response = Response<ResBody>> + Clone + Send + 'static, S: Service<Request<Body>, Response = Response<ResBody>> + Clone + Send + 'static,
ResBody: http_body::Body + Send + 'static, ResBody: HttpBody + Send + 'static,
ResBody::Data: Send, ResBody::Data: Send,
ResBody::Error: Into<BoxError>, ResBody::Error: Into<BoxError>,
S::Future: Send, S::Future: Send,

View File

@ -1,4 +1,5 @@
use crate::{ use crate::{
body::{Bytes, Empty},
error_handling::HandleErrorLayer, error_handling::HandleErrorLayer,
extract::{self, Path}, extract::{self, Path},
handler::Handler, handler::Handler,
@ -7,7 +8,6 @@ use crate::{
test_helpers::*, test_helpers::*,
BoxError, Json, Router, BoxError, Json, Router,
}; };
use bytes::Bytes;
use http::{Method, Request, Response, StatusCode, Uri}; use http::{Method, Request, Response, StatusCode, Uri};
use hyper::Body; use hyper::Body;
use serde::Deserialize; use serde::Deserialize;
@ -234,7 +234,7 @@ async fn wrong_method_service() {
struct Svc; struct Svc;
impl<R> Service<R> for Svc { impl<R> Service<R> for Svc {
type Response = Response<http_body::Empty<Bytes>>; type Response = Response<Empty<Bytes>>;
type Error = Infallible; type Error = Infallible;
type Future = Ready<Result<Self::Response, Self::Error>>; type Future = Ready<Result<Self::Response, Self::Error>>;
@ -243,7 +243,7 @@ async fn wrong_method_service() {
} }
fn call(&mut self, _req: R) -> Self::Future { fn call(&mut self, _req: R) -> Self::Future {
ready(Ok(Response::new(http_body::Empty::new()))) ready(Ok(Response::new(Empty::new())))
} }
} }

View File

@ -1,5 +1,6 @@
#![allow(clippy::blacklisted_name)] #![allow(clippy::blacklisted_name)]
use crate::body::HttpBody;
use crate::BoxError; use crate::BoxError;
use http::{ use http::{
header::{HeaderName, HeaderValue}, header::{HeaderName, HeaderValue},
@ -28,7 +29,7 @@ impl TestClient {
pub(crate) fn new<S, ResBody>(svc: S) -> Self pub(crate) fn new<S, ResBody>(svc: S) -> Self
where where
S: Service<Request<Body>, Response = http::Response<ResBody>> + Clone + Send + 'static, S: Service<Request<Body>, Response = http::Response<ResBody>> + Clone + Send + 'static,
ResBody: http_body::Body + Send + 'static, ResBody: HttpBody + Send + 'static,
ResBody::Data: Send, ResBody::Data: Send,
ResBody::Error: Into<BoxError>, ResBody::Error: Into<BoxError>,
S::Future: Send, S::Future: Send,

View File

@ -1,4 +1,4 @@
use bytes::Bytes; use crate::body::Bytes;
use pin_project_lite::pin_project; use pin_project_lite::pin_project;
use std::fmt; use std::fmt;
use std::ops::Deref; use std::ops::Deref;