{"record":{"id":"598139005a01e20e","repo":"seanmonstar/warp","slug":"payload-too-large","errorCode":null,"errorMessage":"payload_too_large","messagePattern":"payload_too_large","errorType":"http","errorClass":"PayloadTooLarge","httpStatus":413,"severity":"error","filePath":"src/filters/body.rs","lineNumber":61,"sourceCode":"/// ```\n/// use warp::Filter;\n///\n/// // Limit the upload to 4kb...\n/// let upload = warp::body::content_length_limit(4096)\n///     .and(warp::body::aggregate());\n/// ```\npub fn content_length_limit(limit: u64) -> impl Filter<Extract = (), Error = Rejection> + Copy {\n    crate::filters::header::header2()\n        .map_err(crate::filter::Internal, |_| {\n            tracing::debug!(\"content-length missing\");\n            reject::length_required()\n        })\n        .and_then(move |ContentLength(length)| {\n            if length <= limit {\n                future::ok(())\n            } else {\n                tracing::debug!(\"content-length: {} is over limit {}\", length, limit);\n                future::err(reject::payload_too_large())\n            }\n        })\n        .untuple_one()\n}\n\n/// Create a `Filter` that extracts the request body as a `futures::Stream`.\n///\n/// If other filters have already extracted the body, this filter will reject\n/// with a `500 Internal Server Error`.\n///\n/// For example usage, please take a look at [examples/stream.rs](https://github.com/seanmonstar/warp/blob/master/examples/stream.rs).\n///\n/// # Warning\n///\n/// This does not have a default size limit, it would be wise to use one to\n/// prevent a overly large request from using too much memory.\npub fn stream(\n) -> impl Filter<Extract = (impl Stream<Item = Result<impl Buf, crate::Error>>,), Error = Rejection> + Copy","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/seanmonstar/warp/blob/ff34d7213ed55ec342304aa7ff6ac4b351da9e66/src/filters/body.rs#L43-L79","documentation":"warp::body::content_length_limit(limit) rejects the request with a 413 Payload Too Large rejection when the request's Content-Length header exceeds the configured limit. It is a generic guard comparing the declared body size against `limit`; if the Content-Length header is absent entirely, the filter instead yields a 411 Length Required rejection.","triggerScenarios":"Thrown at src/filters/body.rs:61 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Raise the limit passed to content_length_limit to accommodate legitimate large uploads","Compress or chunk large request bodies client-side before uploading","Have the client set a correct Content-Length and trim the payload to the allowed size","Handle the 413 rejection with .recover() and return a clear error message stating the maximum accepted size"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"ff34d7213ed55ec342304aa7ff6ac4b351da9e66","analyzedAt":"2026-09-09T16:57:46.316Z","contentChangedAt":"2026-09-09T16:57:46.316Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}