pub fn aggregate(
) -> impl Filter<Extract = (impl Buf,), Error = Rejection> + Copy
Expand description

Returns a Filter that matches any request and extracts a Future of an aggregated body.

The Buf may contain multiple, non-contiguous buffers. This can be more performant (by reducing copies) when receiving large bodies.

Warning

This does not have a default size limit, it would be wise to use one to prevent a overly large request from using too much memory.

Example

use warp::{Buf, Filter};

fn full_body(mut body: impl Buf) {
    // It could have several non-contiguous slices of memory...
    while body.has_remaining() {
        println!("slice = {:?}", body.chunk());
        let cnt = body.chunk().len();
        body.advance(cnt);
    }
}

let route = warp::body::content_length_limit(1024 * 32)
    .and(warp::body::aggregate())
    .map(full_body);
Examples found in repository?
src/filters/body.rs (line 210)
208
209
210
211
212
213
214
215
216
217
pub fn form<T: DeserializeOwned + Send>() -> impl Filter<Extract = (T,), Error = Rejection> + Copy {
    is_content_type::<Form>()
        .and(aggregate())
        .and_then(|buf| async move {
            Form::decode(buf).map_err(|err| {
                tracing::debug!("request form body error: {}", err);
                reject::known(BodyDeserializeError { cause: err })
            })
        })
}