Skip to content

Commit b7cd407

Browse files
authored
chore(volo-http): fix previously missed changes to Body (#531)
Signed-off-by: Yu Li <[email protected]>
1 parent 469d483 commit b7cd407

File tree

3 files changed

+10
-13
lines changed

3 files changed

+10
-13
lines changed

volo-http/src/body.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,10 @@ pub struct Body {
3636
enum BodyRepr {
3737
/// Complete [`Bytes`], with a certain size and content
3838
Full(#[pin] Full<Bytes>),
39-
/// Wrapper of [`hyper::body::Incoming`], it usually appers in request of server or response of
40-
/// client.
39+
/// Wrapper of [`Incoming`], it usually appears in request of server or response of client.
4140
///
42-
/// Althrough [`hyper::body::Incoming`] implements [`http_body::Body`], the type is so commonly
43-
/// used, we wrap it here as [`Body::Hyper`] to avoid cost of [`Box`] with dynamic dispatch.
41+
/// Althrough [`Incoming`] implements [`http_body::Body`], the type is so commonly used, we
42+
/// wrap it here as [`BodyRepr::Hyper`] to avoid cost of [`Box`] with dynamic dispatch.
4443
Hyper(#[pin] Incoming),
4544
/// Boxed stream with `Item = Result<Frame<Bytes>, BoxError>`
4645
Stream(#[pin] StreamBody<BoxStream<'static, Result<Frame<Bytes>, BoxError>>>),
@@ -62,7 +61,7 @@ impl Body {
6261
}
6362
}
6463

65-
/// Create a body by [`hyper::body::Incoming`].
64+
/// Create a body by [`Incoming`].
6665
///
6766
/// Compared to [`Body::from_body`], this function avoids overhead of allocating by [`Box`]
6867
/// and dynamic dispatch by [`dyn http_body::Body`][http_body::Body].

volo-http/src/request.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ use url::Url;
1515
#[cfg(feature = "client")]
1616
pub type ClientRequest<B = crate::body::Body> = Request<B>;
1717

18-
/// [`Request`] with [`Incoming`] as default body.
18+
/// [`Request`] with [`Body`] as default body.
1919
///
20-
/// [`Incoming`]: hyper::body::Incoming
20+
/// [`Body`]: crate::body::Body
2121
#[cfg(feature = "server")]
2222
pub type ServerRequest<B = crate::body::Body> = Request<B>;
2323

volo-http/src/server/extract.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use http::{
1616
};
1717
use http_body::Body;
1818
use http_body_util::BodyExt;
19-
use hyper::body::Incoming;
2019
use volo::{context::Context, net::Address};
2120

2221
use super::IntoResponse;
@@ -64,7 +63,7 @@ pub trait FromContext: Sized {
6463
///
6564
/// [`FromRequest`] will consume [`ServerRequest`], so it can only be used once in a handler. If
6665
/// your extractor does not need to consume [`ServerRequest`], please use [`FromContext`] instead.
67-
pub trait FromRequest<B = Incoming, M = private::ViaRequest>: Sized {
66+
pub trait FromRequest<B = crate::body::Body, M = private::ViaRequest>: Sized {
6867
/// If the extractor fails, it will return this `Rejection` type.
6968
///
7069
/// The `Rejection` should implement [`IntoResponse`]. If extractor fails in handler, the
@@ -614,10 +613,9 @@ mod extract_tests {
614613
use std::convert::Infallible;
615614

616615
use http::request::Parts;
617-
use hyper::body::Incoming;
618616

619617
use super::{FromContext, FromRequest};
620-
use crate::{context::ServerContext, server::handler::Handler};
618+
use crate::{body::Body, context::ServerContext, server::handler::Handler};
621619

622620
struct SomethingFromCx;
623621

@@ -638,7 +636,7 @@ mod extract_tests {
638636
async fn from_request(
639637
_: &mut ServerContext,
640638
_: Parts,
641-
_: Incoming,
639+
_: Body,
642640
) -> Result<Self, Self::Rejection> {
643641
unimplemented!()
644642
}
@@ -648,7 +646,7 @@ mod extract_tests {
648646
fn extractor() {
649647
fn assert_handler<H, T>(_: H)
650648
where
651-
H: Handler<T, Incoming, Infallible>,
649+
H: Handler<T, Body, Infallible>,
652650
{
653651
}
654652

0 commit comments

Comments
 (0)