pub struct ReqBody { /* private fields */ }Expand description
ReqBody implements an asynchronous streaming mechanism for HTTP request bodies.
§Design Goals
The main design goals of ReqBody are:
- Provide efficient streaming of request bodies without buffering entire payload in memory
- Bridge the gap between low-level payload streams and high-level http_body::Body interface
- Support concurrent processing of request handling and body streaming
- Allow proper cleanup of unread body data to maintain protocol correctness
§Architecture
ReqBody uses a channel-based architecture:
ReqBody: Consumer side that implements http_body::BodyReqBodySender: Producer side that reads from raw payload stream- They communicate through a mpsc channel and oneshot channels
§Example Flow
- HttpConnection creates ReqBody/ReqBodySender pair
- ReqBody is passed to request handler for body consumption
- ReqBodySender runs concurrently to stream payload chunks
- If handler doesn’t read entire body, remaining data is skipped
Implementations§
Source§impl ReqBody
impl ReqBody
Sourcepub fn body_channel<S>(
payload_stream: &mut S,
) -> (ReqBody, ReqBodySender<'_, S>)
pub fn body_channel<S>( payload_stream: &mut S, ) -> (ReqBody, ReqBodySender<'_, S>)
Creates a body streaming channel pair for processing HTTP request bodies.
This is the main entry point for setting up request body streaming. It creates the necessary channels and returns both consumer and producer components.
The returned ReqBody implements http_body::Body and can be passed to request handlers, while ReqBodySender handles reading from the underlying stream.
Trait Implementations§
Source§impl Body for ReqBody
Implements standard HTTP body interface for request bodies.
impl Body for ReqBody
Implements standard HTTP body interface for request bodies.
This implementation bridges our custom streaming mechanism with the standard http_body::Body trait, allowing ReqBody to work seamlessly with HTTP handlers and middleware that expect the standard interface.
Source§type Error = ParseError
type Error = ParseError
Body might generate.Source§fn poll_frame(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Option<Result<Frame<Self::Data>, Self::Error>>>
fn poll_frame( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Option<Result<Frame<Self::Data>, Self::Error>>>
Source§fn is_end_stream(&self) -> bool
fn is_end_stream(&self) -> bool
true when the end of stream has been reached. Read moreAuto Trait Implementations§
impl Freeze for ReqBody
impl !RefUnwindSafe for ReqBody
impl Send for ReqBody
impl Sync for ReqBody
impl Unpin for ReqBody
impl !UnwindSafe for ReqBody
Blanket Implementations§
Source§impl<T> BodyExt for T
impl<T> BodyExt for T
Source§fn frame(&mut self) -> Frame<'_, Self>where
Self: Unpin,
fn frame(&mut self) -> Frame<'_, Self>where
Self: Unpin,
Frame, if any.Source§fn map_frame<F, B>(self, f: F) -> MapFrame<Self, F>
fn map_frame<F, B>(self, f: F) -> MapFrame<Self, F>
Source§fn map_err<F, E>(self, f: F) -> MapErr<Self, F>
fn map_err<F, E>(self, f: F) -> MapErr<Self, F>
Source§fn boxed_unsync(self) -> UnsyncBoxBody<Self::Data, Self::Error>
fn boxed_unsync(self) -> UnsyncBoxBody<Self::Data, Self::Error>
Source§fn collect(self) -> Collect<Self>where
Self: Sized,
fn collect(self) -> Collect<Self>where
Self: Sized,
Collected body which will collect all the DATA frames
and trailers.Source§fn with_trailers<F>(self, trailers: F) -> WithTrailers<Self, F>
fn with_trailers<F>(self, trailers: F) -> WithTrailers<Self, F>
Source§fn into_data_stream(self) -> BodyDataStream<Self>where
Self: Sized,
fn into_data_stream(self) -> BodyDataStream<Self>where
Self: Sized,
BodyDataStream.