Struct Payload
pub struct Payload(/* private fields */);Expand description
Extract a request’s raw payload stream.
See PayloadConfig for important notes when using this advanced extractor.
§Examples
use std::future::Future;
use futures_util::StreamExt as _;
use actix_web::{post, web};
// `body: web::Payload` parameter extracts raw payload stream from request
#[post("/")]
async fn index(mut body: web::Payload) -> actix_web::Result<String> {
    // for demonstration only; in a normal case use the `Bytes` extractor
    // collect payload stream into a bytes object
    let mut bytes = web::BytesMut::new();
    while let Some(item) = body.next().await {
        bytes.extend_from_slice(&item?);
    }
    Ok(format!("Request Body Bytes:\n{:?}", bytes))
}Implementations§
§impl Payload
 
impl Payload
pub fn into_inner(self) -> Payload
pub fn into_inner(self) -> Payload
Unwrap to inner Payload type.
pub async fn to_bytes_limited(
    self,
    limit: usize,
) -> Result<Result<Bytes, Error>, BodyLimitExceeded>
pub async fn to_bytes_limited( self, limit: usize, ) -> Result<Result<Bytes, Error>, BodyLimitExceeded>
Buffers payload from request up to limit bytes.
This method is preferred over Payload::to_bytes() since it will not lead to unexpected
memory exhaustion from massive payloads. Note that the other primitive extractors such as
Bytes and String, as well as extractors built on top of them, already have this sort
of protection according to the configured (or default) PayloadConfig.
§Errors
- The outer error type, 
BodyLimitExceeded, is returned when the payload is larger thanlimit. - The inner error type is the normal Actix Web error and is only returned if the payload stream yields an error for some reason. Such cases are usually caused by unrecoverable connection issues.
 
§Examples
use actix_web::{error, web::Payload, Responder};
async fn limited_payload_handler(pl: Payload) -> actix_web::Result<impl Responder> {
    match pl.to_bytes_limited(5).await {
        Ok(res) => res,
        Err(err) => Err(error::ErrorPayloadTooLarge(err)),
    }
}pub async fn to_bytes(self) -> Result<Bytes, Error>
pub async fn to_bytes(self) -> Result<Bytes, Error>
Buffers entire payload from request.
Use of this method is discouraged unless you know for certain that requests will not be
large enough to exhaust memory. If this is not known, prefer Payload::to_bytes_limited()
or one of the higher level extractors like Bytes or String that implement size
limits according to the configured (or default) PayloadConfig.
§Errors
An error is only returned if the payload stream yields an error for some reason. Such cases are usually caused by unrecoverable connection issues.
§Examples
use actix_web::{error, web::Payload, Responder};
async fn payload_handler(pl: Payload) -> actix_web::Result<impl Responder> {
    pl.to_bytes().await
}Trait Implementations§
§impl Apiv2Schema for Payload
 
impl Apiv2Schema for Payload
§fn name() -> Option<String>
 
fn name() -> Option<String>
§fn description() -> &'static str
 
fn description() -> &'static str
§fn raw_schema() -> DefaultSchemaRaw
 
fn raw_schema() -> DefaultSchemaRaw
§fn schema_with_ref() -> DefaultSchemaRaw
 
fn schema_with_ref() -> DefaultSchemaRaw
§fn security_scheme() -> Option<SecurityScheme>
 
fn security_scheme() -> Option<SecurityScheme>
fn header_parameter_schema() -> Vec<Parameter<DefaultSchemaRaw>>
§impl FromRequest for Payload
See here for example of usage as an extractor.
 
impl FromRequest for Payload
See here for example of usage as an extractor.
§type Future = Ready<Result<Payload, <Payload as FromRequest>::Error>>
 
type Future = Ready<Result<Payload, <Payload as FromRequest>::Error>>
Self. Read more§fn from_request(
    _: &HttpRequest,
    payload: &mut Payload,
) -> <Payload as FromRequest>::Future
 
fn from_request( _: &HttpRequest, payload: &mut Payload, ) -> <Payload as FromRequest>::Future
Self from request parts asynchronously.§fn extract(req: &HttpRequest) -> Self::Future
 
fn extract(req: &HttpRequest) -> Self::Future
Self from request head asynchronously. Read more§impl OperationModifier for Payload
 
impl OperationModifier for Payload
§fn update_parameter(
    op: &mut Operation<Parameter<DefaultSchemaRaw>, Response<DefaultSchemaRaw>>,
)
 
fn update_parameter( op: &mut Operation<Parameter<DefaultSchemaRaw>, Response<DefaultSchemaRaw>>, )
§fn update_response(
    _op: &mut Operation<Parameter<DefaultSchemaRaw>, Response<DefaultSchemaRaw>>,
)
 
fn update_response( _op: &mut Operation<Parameter<DefaultSchemaRaw>, Response<DefaultSchemaRaw>>, )
§fn update_definitions(map: &mut BTreeMap<String, DefaultSchemaRaw>)
 
fn update_definitions(map: &mut BTreeMap<String, DefaultSchemaRaw>)
§fn update_security(
    op: &mut Operation<Parameter<DefaultSchemaRaw>, Response<DefaultSchemaRaw>>,
)
 
fn update_security( op: &mut Operation<Parameter<DefaultSchemaRaw>, Response<DefaultSchemaRaw>>, )
§fn update_security_definitions(map: &mut BTreeMap<String, SecurityScheme>)
 
fn update_security_definitions(map: &mut BTreeMap<String, SecurityScheme>)
§impl Stream for Payload
 
impl Stream for Payload
Auto Trait Implementations§
impl Freeze for Payload
impl !RefUnwindSafe for Payload
impl !Send for Payload
impl !Sync for Payload
impl Unpin for Payload
impl !UnwindSafe for Payload
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
    T: ?Sized,
 
impl<T> BorrowMut<T> for Twhere
    T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
 
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
 
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
 
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
 
fn in_current_span(self) -> Instrumented<Self>
§impl<T> StreamExt for Twhere
    T: Stream + ?Sized,
 
impl<T> StreamExt for Twhere
    T: Stream + ?Sized,
§fn next(&mut self) -> Next<'_, Self>where
    Self: Unpin,
 
fn next(&mut self) -> Next<'_, Self>where
    Self: Unpin,
§fn into_future(self) -> StreamFuture<Self>
 
fn into_future(self) -> StreamFuture<Self>
§fn map<T, F>(self, f: F) -> Map<Self, F>
 
fn map<T, F>(self, f: F) -> Map<Self, F>
§fn enumerate(self) -> Enumerate<Self>where
    Self: Sized,
 
fn enumerate(self) -> Enumerate<Self>where
    Self: Sized,
§fn filter<Fut, F>(self, f: F) -> Filter<Self, Fut, F>
 
fn filter<Fut, F>(self, f: F) -> Filter<Self, Fut, F>
§fn filter_map<Fut, T, F>(self, f: F) -> FilterMap<Self, Fut, F>
 
fn filter_map<Fut, T, F>(self, f: F) -> FilterMap<Self, Fut, F>
§fn then<Fut, F>(self, f: F) -> Then<Self, Fut, F>
 
fn then<Fut, F>(self, f: F) -> Then<Self, Fut, F>
§fn collect<C>(self) -> Collect<Self, C>
 
fn collect<C>(self) -> Collect<Self, C>
§fn unzip<A, B, FromA, FromB>(self) -> Unzip<Self, FromA, FromB>
 
fn unzip<A, B, FromA, FromB>(self) -> Unzip<Self, FromA, FromB>
§fn concat(self) -> Concat<Self>
 
fn concat(self) -> Concat<Self>
§fn count(self) -> Count<Self>where
    Self: Sized,
 
fn count(self) -> Count<Self>where
    Self: Sized,
§fn fold<T, Fut, F>(self, init: T, f: F) -> Fold<Self, Fut, T, F>
 
fn fold<T, Fut, F>(self, init: T, f: F) -> Fold<Self, Fut, T, F>
§fn any<Fut, F>(self, f: F) -> Any<Self, Fut, F>
 
fn any<Fut, F>(self, f: F) -> Any<Self, Fut, F>
true if any element in stream satisfied a predicate. Read more§fn all<Fut, F>(self, f: F) -> All<Self, Fut, F>
 
fn all<Fut, F>(self, f: F) -> All<Self, Fut, F>
true if all element in stream satisfied a predicate. Read more§fn flatten(self) -> Flatten<Self>where
    Self::Item: Stream,
    Self: Sized,
 
fn flatten(self) -> Flatten<Self>where
    Self::Item: Stream,
    Self: Sized,
§fn flatten_unordered(
    self,
    limit: impl Into<Option<usize>>,
) -> FlattenUnorderedWithFlowController<Self, ()>
 
fn flatten_unordered( self, limit: impl Into<Option<usize>>, ) -> FlattenUnorderedWithFlowController<Self, ()>
§fn flat_map_unordered<U, F>(
    self,
    limit: impl Into<Option<usize>>,
    f: F,
) -> FlatMapUnordered<Self, U, F>
 
fn flat_map_unordered<U, F>( self, limit: impl Into<Option<usize>>, f: F, ) -> FlatMapUnordered<Self, U, F>
StreamExt::map] but flattens nested Streams
and polls them concurrently, yielding items in any order, as they made
available. Read more§fn scan<S, B, Fut, F>(self, initial_state: S, f: F) -> Scan<Self, S, Fut, F>
 
fn scan<S, B, Fut, F>(self, initial_state: S, f: F) -> Scan<Self, S, Fut, F>
StreamExt::fold] that holds internal state
and produces a new stream. Read more§fn skip_while<Fut, F>(self, f: F) -> SkipWhile<Self, Fut, F>
 
fn skip_while<Fut, F>(self, f: F) -> SkipWhile<Self, Fut, F>
true. Read more§fn take_while<Fut, F>(self, f: F) -> TakeWhile<Self, Fut, F>
 
fn take_while<Fut, F>(self, f: F) -> TakeWhile<Self, Fut, F>
true. Read more§fn take_until<Fut>(self, fut: Fut) -> TakeUntil<Self, Fut>
 
fn take_until<Fut>(self, fut: Fut) -> TakeUntil<Self, Fut>
§fn for_each<Fut, F>(self, f: F) -> ForEach<Self, Fut, F>
 
fn for_each<Fut, F>(self, f: F) -> ForEach<Self, Fut, F>
§fn for_each_concurrent<Fut, F>(
    self,
    limit: impl Into<Option<usize>>,
    f: F,
) -> ForEachConcurrent<Self, Fut, F>
 
fn for_each_concurrent<Fut, F>( self, limit: impl Into<Option<usize>>, f: F, ) -> ForEachConcurrent<Self, Fut, F>
§fn take(self, n: usize) -> Take<Self>where
    Self: Sized,
 
fn take(self, n: usize) -> Take<Self>where
    Self: Sized,
n items of the underlying stream. Read more§fn skip(self, n: usize) -> Skip<Self>where
    Self: Sized,
 
fn skip(self, n: usize) -> Skip<Self>where
    Self: Sized,
n items of the underlying stream. Read more§fn catch_unwind(self) -> CatchUnwind<Self>where
    Self: Sized + UnwindSafe,
 
fn catch_unwind(self) -> CatchUnwind<Self>where
    Self: Sized + UnwindSafe,
§fn boxed<'a>(self) -> Pin<Box<dyn Stream<Item = Self::Item> + Send + 'a>>
 
fn boxed<'a>(self) -> Pin<Box<dyn Stream<Item = Self::Item> + Send + 'a>>
§fn boxed_local<'a>(self) -> Pin<Box<dyn Stream<Item = Self::Item> + 'a>>where
    Self: Sized + 'a,
 
fn boxed_local<'a>(self) -> Pin<Box<dyn Stream<Item = Self::Item> + 'a>>where
    Self: Sized + 'a,
§fn buffered(self, n: usize) -> Buffered<Self>
 
fn buffered(self, n: usize) -> Buffered<Self>
§fn buffer_unordered(self, n: usize) -> BufferUnordered<Self>
 
fn buffer_unordered(self, n: usize) -> BufferUnordered<Self>
§fn zip<St>(self, other: St) -> Zip<Self, St>where
    St: Stream,
    Self: Sized,
 
fn zip<St>(self, other: St) -> Zip<Self, St>where
    St: Stream,
    Self: Sized,
§fn chain<St>(self, other: St) -> Chain<Self, St>where
    St: Stream<Item = Self::Item>,
    Self: Sized,
 
fn chain<St>(self, other: St) -> Chain<Self, St>where
    St: Stream<Item = Self::Item>,
    Self: Sized,
§fn peekable(self) -> Peekable<Self>where
    Self: Sized,
 
fn peekable(self) -> Peekable<Self>where
    Self: Sized,
peek method. Read more§fn chunks(self, capacity: usize) -> Chunks<Self>where
    Self: Sized,
 
fn chunks(self, capacity: usize) -> Chunks<Self>where
    Self: Sized,
§fn ready_chunks(self, capacity: usize) -> ReadyChunks<Self>where
    Self: Sized,
 
fn ready_chunks(self, capacity: usize) -> ReadyChunks<Self>where
    Self: Sized,
§fn forward<S>(self, sink: S) -> Forward<Self, S>where
    S: Sink<Self::Ok, Error = Self::Error>,
    Self: Sized + TryStream,
 
fn forward<S>(self, sink: S) -> Forward<Self, S>where
    S: Sink<Self::Ok, Error = Self::Error>,
    Self: Sized + TryStream,
§fn inspect<F>(self, f: F) -> Inspect<Self, F>
 
fn inspect<F>(self, f: F) -> Inspect<Self, F>
§fn left_stream<B>(self) -> Either<Self, B>where
    B: Stream<Item = Self::Item>,
    Self: Sized,
 
fn left_stream<B>(self) -> Either<Self, B>where
    B: Stream<Item = Self::Item>,
    Self: Sized,
§fn right_stream<B>(self) -> Either<B, Self>where
    B: Stream<Item = Self::Item>,
    Self: Sized,
 
fn right_stream<B>(self) -> Either<B, Self>where
    B: Stream<Item = Self::Item>,
    Self: Sized,
§fn poll_next_unpin(&mut self, cx: &mut Context<'_>) -> Poll<Option<Self::Item>>where
    Self: Unpin,
 
fn poll_next_unpin(&mut self, cx: &mut Context<'_>) -> Poll<Option<Self::Item>>where
    Self: Unpin,
Stream::poll_next] on Unpin
stream types.§fn select_next_some(&mut self) -> SelectNextSome<'_, Self>where
    Self: Unpin + FusedStream,
 
fn select_next_some(&mut self) -> SelectNextSome<'_, Self>where
    Self: Unpin + FusedStream,
§impl<S, T, E> TryStream for S
 
impl<S, T, E> TryStream for S
§impl<S> TryStreamExt for Swhere
    S: TryStream + ?Sized,
 
impl<S> TryStreamExt for Swhere
    S: TryStream + ?Sized,
§fn err_into<E>(self) -> ErrInto<Self, E>
 
fn err_into<E>(self) -> ErrInto<Self, E>
§fn map_ok<T, F>(self, f: F) -> MapOk<Self, F>
 
fn map_ok<T, F>(self, f: F) -> MapOk<Self, F>
§fn map_err<E, F>(self, f: F) -> MapErr<Self, F>
 
fn map_err<E, F>(self, f: F) -> MapErr<Self, F>
§fn and_then<Fut, F>(self, f: F) -> AndThen<Self, Fut, F>
 
fn and_then<Fut, F>(self, f: F) -> AndThen<Self, Fut, F>
f. Read more§fn or_else<Fut, F>(self, f: F) -> OrElse<Self, Fut, F>
 
fn or_else<Fut, F>(self, f: F) -> OrElse<Self, Fut, F>
f. Read more§fn inspect_ok<F>(self, f: F) -> InspectOk<Self, F>
 
fn inspect_ok<F>(self, f: F) -> InspectOk<Self, F>
§fn inspect_err<F>(self, f: F) -> InspectErr<Self, F>
 
fn inspect_err<F>(self, f: F) -> InspectErr<Self, F>
§fn into_stream(self) -> IntoStream<Self>where
    Self: Sized,
 
fn into_stream(self) -> IntoStream<Self>where
    Self: Sized,
§fn try_next(&mut self) -> TryNext<'_, Self>where
    Self: Unpin,
 
fn try_next(&mut self) -> TryNext<'_, Self>where
    Self: Unpin,
§fn try_for_each<Fut, F>(self, f: F) -> TryForEach<Self, Fut, F>
 
fn try_for_each<Fut, F>(self, f: F) -> TryForEach<Self, Fut, F>
§fn try_skip_while<Fut, F>(self, f: F) -> TrySkipWhile<Self, Fut, F>
 
fn try_skip_while<Fut, F>(self, f: F) -> TrySkipWhile<Self, Fut, F>
true. Read more§fn try_take_while<Fut, F>(self, f: F) -> TryTakeWhile<Self, Fut, F>
 
fn try_take_while<Fut, F>(self, f: F) -> TryTakeWhile<Self, Fut, F>
true. Read more§fn try_for_each_concurrent<Fut, F>(
    self,
    limit: impl Into<Option<usize>>,
    f: F,
) -> TryForEachConcurrent<Self, Fut, F>
 
fn try_for_each_concurrent<Fut, F>( self, limit: impl Into<Option<usize>>, f: F, ) -> TryForEachConcurrent<Self, Fut, F>
§fn try_collect<C>(self) -> TryCollect<Self, C>
 
fn try_collect<C>(self) -> TryCollect<Self, C>
§fn try_chunks(self, capacity: usize) -> TryChunks<Self>where
    Self: Sized,
 
fn try_chunks(self, capacity: usize) -> TryChunks<Self>where
    Self: Sized,
§fn try_ready_chunks(self, capacity: usize) -> TryReadyChunks<Self>where
    Self: Sized,
 
fn try_ready_chunks(self, capacity: usize) -> TryReadyChunks<Self>where
    Self: Sized,
§fn try_filter<Fut, F>(self, f: F) -> TryFilter<Self, Fut, F>
 
fn try_filter<Fut, F>(self, f: F) -> TryFilter<Self, Fut, F>
§fn try_filter_map<Fut, F, T>(self, f: F) -> TryFilterMap<Self, Fut, F>
 
fn try_filter_map<Fut, F, T>(self, f: F) -> TryFilterMap<Self, Fut, F>
§fn try_flatten_unordered(
    self,
    limit: impl Into<Option<usize>>,
) -> TryFlattenUnordered<Self>
 
fn try_flatten_unordered( self, limit: impl Into<Option<usize>>, ) -> TryFlattenUnordered<Self>
§fn try_flatten(self) -> TryFlatten<Self>
 
fn try_flatten(self) -> TryFlatten<Self>
§fn try_fold<T, Fut, F>(self, init: T, f: F) -> TryFold<Self, Fut, T, F>
 
fn try_fold<T, Fut, F>(self, init: T, f: F) -> TryFold<Self, Fut, T, F>
§fn try_concat(self) -> TryConcat<Self>
 
fn try_concat(self) -> TryConcat<Self>
§fn try_buffer_unordered(self, n: usize) -> TryBufferUnordered<Self>where
    Self::Ok: TryFuture<Error = Self::Error>,
    Self: Sized,
 
fn try_buffer_unordered(self, n: usize) -> TryBufferUnordered<Self>where
    Self::Ok: TryFuture<Error = Self::Error>,
    Self: Sized,
§fn try_buffered(self, n: usize) -> TryBuffered<Self>where
    Self::Ok: TryFuture<Error = Self::Error>,
    Self: Sized,
 
fn try_buffered(self, n: usize) -> TryBuffered<Self>where
    Self::Ok: TryFuture<Error = Self::Error>,
    Self: Sized,
§fn try_poll_next_unpin(
    &mut self,
    cx: &mut Context<'_>,
) -> Poll<Option<Result<Self::Ok, Self::Error>>>where
    Self: Unpin,
 
fn try_poll_next_unpin(
    &mut self,
    cx: &mut Context<'_>,
) -> Poll<Option<Result<Self::Ok, Self::Error>>>where
    Self: Unpin,
TryStream::try_poll_next] on Unpin
stream types.§fn into_async_read(self) -> IntoAsyncRead<Self>
 
fn into_async_read(self) -> IntoAsyncRead<Self>
AsyncBufRead. Read more§fn try_all<Fut, F>(self, f: F) -> TryAll<Self, Fut, F>
 
fn try_all<Fut, F>(self, f: F) -> TryAll<Self, Fut, F>
Err is encountered or if an Ok item is found
that does not satisfy the predicate. Read more