From cec9f02ebc387b1e3ab25384e4749372545b3e86 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Sun, 11 Nov 2018 13:24:14 +0100 Subject: [PATCH] limit allowed body size --- src/main.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 0b9b5a46..d98788c2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -50,8 +50,16 @@ fn get_request_parameters_async<'a>( req_body: Body, ) -> Box + Send + 'a> { - let resp = req_body.concat2() + let resp = req_body .map_err(|err| format_err!("Promlems reading request body: {}", err)) + .fold(Vec::new(), |mut acc, chunk| { + if acc.len() + chunk.len() < 64*1024 { //fimxe: max request body size? + acc.extend_from_slice(&*chunk); + ok(acc) + } else { + err(format_err!("Request body too large")) + } + }) .and_then(move |body| { let bytes = String::from_utf8(body.to_vec())?; // why copy??