Search code examples
rustactix-web

Actix PayloadConfig limit not respected


I've got problem with setting the payload limit in Actix. No matter how I try to configure it (with app_data, data, on service level etc) I always get 413 http response with body A payload reached size limit. and following log: Error in response: Overflow

Here's the code

    HttpServer::new(move || {
        App::new()
            .data(app_config.clone())
            .app_data(web::PayloadConfig::new(50_242_880))
            .data(Client::new())
            .wrap(middleware::Logger::default())
            .route("/{path:.*}", web::get().to(proxy))
    }).bind(server_address)
        ?.run()
        .await

where proxy is:

pub async fn proxy(
    original_request: HttpRequest,
    body: Option<web::Bytes>,
    client: web::Data<Client>,
    app_config: web::Data<AppConfig>
) -> Result<HttpResponse, Error> {

I've also tried to set other configs e.g.

            .app_data(web::JsonConfig::default().limit(5_242_880))
            .app_data(actix_web::web::Bytes::configure(|cfg| {
                cfg.limit(5_242_880)
            }))

but it didn't work either


Solution

  • It turned out that it was my bad. There're two limits

    1. payload limit that server can handle for request
    2. http client response limit

    Both produces the same log, so it's hard to know which limit you've hit. To change HTTP client response body limit one should do:

                request.send()
                    .await
                    .map_err(Error::from)?
                    .body()
                    .limit(1024)