plane_dynamic_proxy/
body.rs

1//! Provides a concrete, boxed body and error type.
2
3use bytes::Bytes;
4use http_body::Body;
5use http_body_util::combinators::UnsyncBoxBody;
6use http_body_util::{BodyExt, Empty};
7
8pub type BoxedError = Box<dyn std::error::Error + Send + Sync>;
9
10pub type SimpleBody = UnsyncBoxBody<Bytes, BoxedError>;
11
12pub fn to_simple_body<B>(body: B) -> SimpleBody
13where
14    B: Body<Data = Bytes> + Send + 'static,
15    B::Error: Into<BoxedError>,
16{
17    body.map_err(|e| e.into() as BoxedError).boxed_unsync()
18}
19
20pub fn simple_empty_body() -> SimpleBody {
21    Empty::<Bytes>::new()
22        .map_err(|_| unreachable!("Infallable"))
23        .boxed_unsync()
24}