Module rama::http::layer::body_limit

Expand description

Apply a limit to the request body.

§Example

use rama_http::{Body, Request, Response};
use std::convert::Infallible;
use rama_core::service::service_fn;
use rama_core::{Context, Layer, Service};
use rama_http::layer::body_limit::BodyLimitLayer;

async fn handle<B>(_: Request<B>) -> Result<Response, Infallible> {
    // ...
}

let mut svc = (
     // Limit the request body to 2MB
    BodyLimitLayer::new(2*1024*1024),
).layer(service_fn(handle));

// Call the service
let request = Request::new(Body::default());

svc.serve(Context::default(), request).await?;

Structs§