Files
axum/src/body.rs
T

37 lines
833 B
Rust
Raw Normal View History

2021-06-07 15:45:19 +02:00
//! HTTP body utilities.
2021-08-21 15:01:30 +02:00
use crate::BoxError;
2021-08-07 19:56:44 +02:00
use crate::Error;
2021-05-30 04:28:24 +02:00
2021-08-22 14:41:51 +02:00
mod stream_body;
pub use self::stream_body::StreamBody;
2021-08-07 20:29:24 +02:00
#[doc(no_inline)]
2021-08-08 16:41:17 +02:00
pub use http_body::{Body as HttpBody, Empty, Full};
#[doc(no_inline)]
2021-05-30 13:24:03 +02:00
pub use hyper::body::Body;
2021-08-08 16:41:17 +02:00
#[doc(no_inline)]
pub use bytes::Bytes;
2021-05-30 04:28:24 +02:00
/// A boxed [`Body`] trait object.
2021-06-08 21:21:20 +02:00
///
/// This is used in axum as the response body type for applications. Its
/// necessary to unify multiple response bodies types into one.
2021-08-07 19:56:44 +02:00
pub type BoxBody = http_body::combinators::BoxBody<Bytes, Error>;
2021-05-30 04:28:24 +02:00
/// Convert a [`http_body::Body`] into a [`BoxBody`].
pub fn box_body<B>(body: B) -> BoxBody
where
2021-07-22 13:23:50 +02:00
B: http_body::Body<Data = Bytes> + Send + Sync + 'static,
B::Error: Into<BoxError>,
{
2021-08-07 19:56:44 +02:00
body.map_err(Error::new).boxed()
2021-07-22 13:23:50 +02:00
}
pub(crate) fn empty() -> BoxBody {
box_body(http_body::Empty::new())
2021-06-01 00:34:09 +02:00
}