pavex/request/body/
limit.rs

1use crate::unit::ByteUnit;
2use pavex_macros::methods;
3use ubyte::ToByteUnit;
4
5#[derive(Debug, Clone, Copy)]
6/// An upper limit on the size of incoming request bodies.
7///
8/// Check out the documentation of [`BufferedBody`](crate::request::body::BufferedBody) for more details.
9pub enum BodySizeLimit {
10    /// There is an active limit on the size of incoming request bodies.
11    Enabled {
12        /// The maximum size of incoming request bodies, in bytes.
13        max_size: ByteUnit,
14    },
15    /// There is no limit on the size of incoming request bodies.
16    Disabled,
17}
18
19#[methods]
20impl BodySizeLimit {
21    /// Create a new [`BodySizeLimit`] using the default limit (2 MBs).
22    #[request_scoped(pavex = crate)]
23    pub fn new() -> BodySizeLimit {
24        Self::default()
25    }
26}
27
28impl Default for BodySizeLimit {
29    fn default() -> Self {
30        Self::Enabled {
31            max_size: 2.megabytes(),
32        }
33    }
34}