#[non_exhaustive]pub struct Limits {Show 16 fields
pub max_body_bytes: u64,
pub max_fields: u32,
pub max_name_bytes: u32,
pub max_value_bytes: u32,
pub max_text_bytes: u64,
pub max_parts: u32,
pub max_files: u32,
pub max_file_bytes: u64,
pub max_part_header_bytes: u32,
pub max_part_headers: u16,
pub max_filename_bytes: u32,
pub max_preamble_bytes: u32,
pub max_epilogue_bytes: u32,
pub max_padding_bytes: u8,
pub sniff_bytes: u32,
pub max_token_bytes: u16,
}Expand description
Every budget form-net enforces.
Each budget is checked before the bytes it governs are buffered, stored, or passed on. A limit of 0 means none allowed. A limit larger than the one containing it is capped by it (the effective value is the smaller), so a route sets only the limits it cares about.
| Field | Default |
|---|---|
max_body_bytes | 10 MiB |
max_fields | 1,000 |
max_name_bytes | 256 |
max_value_bytes | 1 MiB |
max_text_bytes | 2 MiB |
max_parts | 100 |
max_files | 20 |
max_file_bytes | 10 MiB |
max_part_header_bytes | 8 KiB |
max_part_headers | 8 |
max_filename_bytes | 1,024 |
max_preamble_bytes | 1 KiB |
max_epilogue_bytes | 1 KiB |
max_padding_bytes | 32 |
sniff_bytes | 0 |
max_token_bytes | 128 |
§Examples
use form_net::Limits;
// A login route: a small body, a few fields, no files.
const LOGIN: Limits = Limits::DEFAULT
.with_max_body_bytes(4 * 1024)
.with_max_fields(8)
.with_max_files(0);
assert!(LOGIN.validate().is_ok());Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.max_body_bytes: u64Every byte fed, both formats, preamble and epilogue included.
max_fields: u32urlencoded pairs; multipart text fields.
max_name_bytes: u32Raw (encoded) name length. Capped by max_body_bytes.
max_value_bytes: u32One urlencoded value or one multipart text field. Capped by
max_text_bytes.
max_text_bytes: u64All text values of one body together. Capped by max_body_bytes.
max_parts: u32Multipart parts of either kind.
max_files: u32Multipart file parts.
max_file_bytes: u64One file part. Capped by max_body_bytes.
max_part_header_bytes: u32One part’s header block, CRLF CRLF included (at least 64).
max_part_headers: u16Header lines per part.
max_filename_bytes: u32A raw filename, or a decoded filename*. Capped by
max_part_header_bytes.
max_preamble_bytes: u32Bytes before the first delimiter. Capped by max_body_bytes.
max_epilogue_bytes: u32Bytes after the close delimiter. Capped by max_body_bytes.
max_padding_bytes: u8Transport padding after a delimiter.
sniff_bytes: u32The sniff window per file part (0: off). Capped by max_file_bytes.
max_token_bytes: u16The captured anti-forgery token. Capped by max_value_bytes.
Implementations§
Source§impl Limits
impl Limits
Sourcepub const fn with_max_body_bytes(self, value: u64) -> Self
pub const fn with_max_body_bytes(self, value: u64) -> Self
Sets max_body_bytes.
Sourcepub const fn with_max_fields(self, value: u32) -> Self
pub const fn with_max_fields(self, value: u32) -> Self
Sets max_fields.
Sourcepub const fn with_max_name_bytes(self, value: u32) -> Self
pub const fn with_max_name_bytes(self, value: u32) -> Self
Sets max_name_bytes.
Sourcepub const fn with_max_value_bytes(self, value: u32) -> Self
pub const fn with_max_value_bytes(self, value: u32) -> Self
Sets max_value_bytes.
Sourcepub const fn with_max_text_bytes(self, value: u64) -> Self
pub const fn with_max_text_bytes(self, value: u64) -> Self
Sets max_text_bytes.
Sourcepub const fn with_max_parts(self, value: u32) -> Self
pub const fn with_max_parts(self, value: u32) -> Self
Sets max_parts.
Sourcepub const fn with_max_files(self, value: u32) -> Self
pub const fn with_max_files(self, value: u32) -> Self
Sets max_files.
Sourcepub const fn with_max_file_bytes(self, value: u64) -> Self
pub const fn with_max_file_bytes(self, value: u64) -> Self
Sets max_file_bytes.
Sourcepub const fn with_max_part_header_bytes(self, value: u32) -> Self
pub const fn with_max_part_header_bytes(self, value: u32) -> Self
Sets max_part_header_bytes.
Sourcepub const fn with_max_part_headers(self, value: u16) -> Self
pub const fn with_max_part_headers(self, value: u16) -> Self
Sets max_part_headers.
Sourcepub const fn with_max_filename_bytes(self, value: u32) -> Self
pub const fn with_max_filename_bytes(self, value: u32) -> Self
Sets max_filename_bytes.
Sourcepub const fn with_max_preamble_bytes(self, value: u32) -> Self
pub const fn with_max_preamble_bytes(self, value: u32) -> Self
Sets max_preamble_bytes.
Sourcepub const fn with_max_epilogue_bytes(self, value: u32) -> Self
pub const fn with_max_epilogue_bytes(self, value: u32) -> Self
Sets max_epilogue_bytes.
Sourcepub const fn with_max_padding_bytes(self, value: u8) -> Self
pub const fn with_max_padding_bytes(self, value: u8) -> Self
Sets max_padding_bytes.
Sourcepub const fn with_sniff_bytes(self, value: u32) -> Self
pub const fn with_sniff_bytes(self, value: u32) -> Self
Sets sniff_bytes.
Sourcepub const fn with_max_token_bytes(self, value: u16) -> Self
pub const fn with_max_token_bytes(self, value: u16) -> Self
Sets max_token_bytes.
Sourcepub fn validate(&self) -> Result<(), FormError>
pub fn validate(&self) -> Result<(), FormError>
Refuses the values no body could satisfy, so a misconfiguration is
found at startup: a max_part_header_bytes below 64 (the shortest
useful Content-Disposition line must fit), or buffer sizes that do
not fit in usize. Every parser constructor and every *_with
function calls it.
§Errors
FormError::InvalidLimits naming the refused field.
§Examples
use form_net::Limits;
assert!(Limits::DEFAULT.validate().is_ok());
let broken = Limits::DEFAULT.with_max_part_header_bytes(16);
assert_eq!(broken.validate().unwrap_err().code(), "invalid_limits");Sourcepub const fn multipart_buffer_len(&self, policy: &Policy) -> usize
pub const fn multipart_buffer_len(&self, policy: &Policy) -> usize
The buffer length the multipart parser needs with these limits and
this policy: the header block, the decoded field name, the decoded
filename* (only under ExtendedFilenamePolicy::AcceptAlone), the
token (only with a token field), and 32 bytes for _charset_.
A const fn, so a stack buffer can be sized at compile time.
§Examples
use form_net::{Limits, Policy};
const LIMITS: Limits = Limits::DEFAULT.with_max_part_header_bytes(1024);
const LEN: usize = LIMITS.multipart_buffer_len(&Policy::DEFAULT);
assert_eq!(LEN, 1024 + 256 + 32);
let buffer = [0u8; LEN];Sourcepub const fn urlencoded_buffer_len(&self) -> usize
pub const fn urlencoded_buffer_len(&self) -> usize
The scratch length the streaming urlencoded parser needs:
max_name_bytes + max_value_bytes + 1 (effective values).
§Examples
use form_net::Limits;
const LIMITS: Limits = Limits::DEFAULT.with_max_text_bytes(1000);
assert_eq!(LIMITS.urlencoded_buffer_len(), 256 + 1000 + 1);