pavex/request/body/
raw_body.rs

1use std::pin::Pin;
2use std::task::{Context, Poll};
3
4use http_body::{Body, Frame};
5use hyper::body::Incoming;
6use pin_project_lite::pin_project;
7
8pin_project! {
9    #[derive(Debug)]
10
11    /// The raw body of the incoming HTTP request.
12    ///
13    /// # Guide
14    ///
15    /// You're looking at the stream of bytes coming from the network.
16    /// There are **no safeguards nor conveniences**.
17    ///
18    /// Check out [the guide](https://pavex.dev/docs/guide/request_data/wire_data/)
19    /// for a thorough introduction to `RawIncomingBody` and guidance on when to use it.
20    pub struct RawIncomingBody {
21        #[pin] inner: Incoming,
22    }
23}
24
25// We just delegate to the underlying `Incoming` `Body` implementation.
26impl Body for RawIncomingBody {
27    type Data = <Incoming as Body>::Data;
28    type Error = <Incoming as Body>::Error;
29
30    fn poll_frame(
31        self: Pin<&mut Self>,
32        cx: &mut Context<'_>,
33    ) -> Poll<Option<Result<Frame<Self::Data>, Self::Error>>> {
34        self.project().inner.poll_frame(cx)
35    }
36}
37
38impl From<Incoming> for RawIncomingBody {
39    fn from(inner: Incoming) -> Self {
40        Self { inner }
41    }
42}