Skip to content

How to gracefully return 413 with RequestBodyLimitLayer for chunked transfer encoding #610

@banool

Description

@banool
  • I have looked for existing issues (including closed) about this

I read this old thread but it didn't really address this problem: tokio-rs/axum#853.

Bug Report

Version

$ cargo tree | grep tower-http
└── tower-http v0.6.6

Platform

$ uname -a
Darwin dportMacbookM4.local 25.0.0 Darwin Kernel Version 25.0.0: Wed Sep 17 21:41:26 PDT 2025; root:xnu-12377.1.9~141/RELEASE_ARM64_T6041 arm64

Crates

axum = "0.7"
tokio = { version = "1", features = ["full"] }
tower = "0.5.2"
tower-http = { version = "0.6.6", features = ["limit"] }
hyper = { version = "1.0", features = ["client", "http1"] }
hyper-util = { version = "0.1", features = ["client-legacy", "http1", "tokio"] }
http-body-util = "0.1"
bytes = "1"
futures-util = "0.3"

Description

I have example code here:

https://github.com/banool/rust-examples/blob/e0e103404ffd1678613fdbe2fe02c12f71ae750a/chunked-limit-demo/src/main.rs

Right now when using the request limit layer you get a client error, rather than a clean 413 response. I was hoping RequestBodyLimitLayer would handle this on my behalf, is there a any chance the layer could be modified to handle this more gracefully? Like making the limited body return an error that results in a 413 response?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions