pub struct Limits { /* private fields */ }Expand description
The work and size bounds every parser enforces.
Every bound is checked before the work it governs, and none allocates: they bound loops. The defaults meet every minimum RFC 9651 section 3 sets for parsers, so a conforming sender is never refused by default.
| Bound | Default | Source |
|---|---|---|
| list members | 1024 | RFC 9651 section 3.1 minimum |
| inner list members | 256 | RFC 9651 section 3.1.1 minimum |
| parameters per item or field | 256 | RFC 9651 section 3.1.2 minimum |
| dictionary members | 1024 | RFC 9651 section 3.2 minimum |
| key length | 256 | RFC 9651 minimum is 64 |
| string length (decoded) | 1024 | RFC 9651 section 3.3.3 minimum |
| token length | 512 | RFC 9651 section 3.3.4 minimum |
| byte sequence length (decoded) | 16384 | RFC 9651 section 3.3.5 minimum |
| empty list elements | 16 | RFC 9110 section 5.6.1.2: “a reasonable number” |
| comment depth | 8 | none in the RFC |
| ranges | 16 | RFC 9110 section 14.2 permits refusal |
| RFC 2231 sections | 32 | none in the RFC |
| encoded words per field | 64 | none in the RFC |
| forwarded hops | 16 | none in the RFC |
A setter may set a bound below the RFC minimum: that is the caller tightening deliberately, and it makes the parser non-conforming for that field.
§Examples
use parse_net::{list, ErrorKind, Limits};
const STRICT: Limits = Limits::DEFAULT.max_list_members(64).max_params(16);
let err = list::parse(b"a, b, c", &Limits::DEFAULT.max_list_members(2)).unwrap_err();
assert_eq!((err.kind(), err.offset()), (ErrorKind::TooManyMembers, 6));Implementations§
Source§impl Limits
impl Limits
Sourcepub const fn new() -> Self
pub const fn new() -> Self
The defaults; the same as Limits::DEFAULT.
Sourcepub const fn max_list_members(self, n: u16) -> Self
pub const fn max_list_members(self, n: u16) -> Self
The most members a list may have (default 1024).
Sourcepub const fn max_inner_list_members(self, n: u16) -> Self
pub const fn max_inner_list_members(self, n: u16) -> Self
The most members a Structured Field inner list may have (default 256).
Sourcepub const fn max_params(self, n: u16) -> Self
pub const fn max_params(self, n: u16) -> Self
The most parameters an item or a field may have (default 256).
Sourcepub const fn max_dictionary_members(self, n: u16) -> Self
pub const fn max_dictionary_members(self, n: u16) -> Self
The most members a Structured Field dictionary may have (default 1024).
Sourcepub const fn max_key_len(self, n: u16) -> Self
pub const fn max_key_len(self, n: u16) -> Self
The longest Structured Field key (default 256).
Sourcepub const fn max_string_len(self, n: u16) -> Self
pub const fn max_string_len(self, n: u16) -> Self
The longest Structured Field string, decoded (default 1024).
Sourcepub const fn max_token_len(self, n: u16) -> Self
pub const fn max_token_len(self, n: u16) -> Self
The longest Structured Field token (default 512).
Sourcepub const fn max_byte_seq_len(self, n: u32) -> Self
pub const fn max_byte_seq_len(self, n: u32) -> Self
The longest Structured Field byte sequence, decoded (default 16384).
Sourcepub const fn max_empty_elements(self, n: u16) -> Self
pub const fn max_empty_elements(self, n: u16) -> Self
The most empty list elements accepted in one field (default 16).
Sourcepub const fn max_comment_depth(self, n: u8) -> Self
pub const fn max_comment_depth(self, n: u8) -> Self
The deepest comment nesting accepted (default 8).
Sourcepub const fn max_ranges(self, n: u16) -> Self
pub const fn max_ranges(self, n: u16) -> Self
The most ranges a Range field may request (default 16).
Sourcepub const fn max_rfc2231_sections(self, n: u8) -> Self
pub const fn max_rfc2231_sections(self, n: u8) -> Self
The most RFC 2231 sections in one parameter (default 32). Values above 32, the size of the reassembly array, are stored as 32.
Sourcepub const fn max_encoded_words(self, n: u16) -> Self
pub const fn max_encoded_words(self, n: u16) -> Self
The most RFC 2047 encoded words in one field (default 64).
Sourcepub const fn allow_leap_second(self, yes: bool) -> Self
pub const fn allow_leap_second(self, yes: bool) -> Self
Whether HTTP-date accepts second 60 (read as 59). Off by default.
Sourcepub const fn duplicate_params(self, p: DuplicatePolicy) -> Self
pub const fn duplicate_params(self, p: DuplicatePolicy) -> Self
What parameter parsers do with a repeated name (default
DuplicatePolicy::Refuse).