mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2025-10-15 19:21:57 +00:00
feat: Proactively read Content-Length to reject oversized uploads
This commit is contained in:
parent
799def70dc
commit
cb8f36444c
1 changed files with 13 additions and 0 deletions
|
@ -34,6 +34,19 @@ pub(super) async fn from(
|
|||
|
||||
let max_body_size = services.server.config.max_request_size;
|
||||
|
||||
// Check if the Content-Length header is present and valid, saves us streaming
|
||||
// the response into memory
|
||||
if let Some(content_length) = parts.headers.get(http::header::CONTENT_LENGTH) {
|
||||
if let Ok(content_length) = content_length
|
||||
.to_str()
|
||||
.map(|s| s.parse::<usize>().unwrap_or_default())
|
||||
{
|
||||
if content_length > max_body_size {
|
||||
return Err(err!(Request(TooLarge("Request body too large"))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let body = axum::body::to_bytes(body, max_body_size)
|
||||
.await
|
||||
.map_err(|e| err!(Request(TooLarge("Request body too large: {e}"))))?;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue