pub struct Body(_);
Expand description
A body object for requests and responses.
Implementations
Create a body object from Bytes
.
Create a body object from String
.
Create a body object from reader.
Create a body object from bytes stream.
Consumes this body object to return a Bytes
that contains all data.
Consumes this body object to return a Vec<u8>
that contains all
data.
Consumes this body object to return a Bytes
that contains all
data, returns Err(ReadBodyError::PayloadTooLarge)
if the length of the
payload exceeds limit
.
Example
use poem::{error::ReadBodyError, handler, http::StatusCode, Body, Endpoint, Request, Result};
#[handler]
async fn index(data: Body) -> Result<()> {
Ok(data.into_bytes_limit(5).await.map(|_| ())?)
}
let req = Request::builder().body("12345");
assert_eq!(index.get_response(req).await.status(), StatusCode::OK);
let req = Request::builder().body("123456");
assert_eq!(
index.get_response(req).await.status(),
StatusCode::PAYLOAD_TOO_LARGE
);
Consumes this body object to return a String
that contains all data.
Consumes this body object to return a reader.
Trait Implementations
Performs the conversion.
fn from_request<'life0, 'async_trait>(
_req: &'a Request,
body: &'life0 mut RequestBody
) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>> where
'a: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait,
fn from_request<'life0, 'async_trait>(
_req: &'a Request,
body: &'life0 mut RequestBody
) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>> where
'a: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait,
Extract from request head and body.
Consume itself and return Response
.
fn with_header<K, V>(self, key: K, value: V) -> WithHeader<Self> where
K: TryInto<HeaderName>,
V: TryInto<HeaderValue>,
Self: Sized,
fn with_header<K, V>(self, key: K, value: V) -> WithHeader<Self> where
K: TryInto<HeaderName>,
V: TryInto<HeaderValue>,
Self: Sized,
Wrap an impl IntoResponse
to add a header. Read more
Wrap an impl IntoResponse
to set a status code. Read more
Auto Trait Implementations
impl !RefUnwindSafe for Body
impl !UnwindSafe for Body
Blanket Implementations
Mutably borrows from an owned value. Read more
Consumes this value returns a poem::Result<T>
.
pub fn vzip(self) -> V
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more