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 9110 parameters under DuplicatePolicy::Refuse: at most 64, param::MAX_CHECKED_PARAMS) | 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 DEFAULT: Self
pub const DEFAULT: Self
The defaults in the table above.
§Examples
use parse_net::Limits;
assert_eq!(Limits::DEFAULT, Limits::default());
let l = parse_net::list::parse(b"a, b, c", &Limits::DEFAULT)?;
assert_eq!(l.len(), 3);Sourcepub const fn new() -> Self
pub const fn new() -> Self
The defaults; the same as Limits::DEFAULT.
§Examples
use parse_net::Limits;
const LIMITS: Limits = Limits::new();
assert_eq!(LIMITS, 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).
§Examples
use parse_net::{list, ErrorKind, Limits};
let two = Limits::DEFAULT.max_list_members(2);
assert_eq!(list::parse(b"a, b", &two)?.len(), 2);
assert_eq!(list::parse(b"a, b, c", &two).unwrap_err().kind(), ErrorKind::TooManyMembers);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).
§Examples
use parse_net::{sfv::Parser, ErrorKind, Limits};
let p = Parser::new(Limits::DEFAULT.max_inner_list_members(2));
assert!(p.list(b"(a b), c").is_ok());
assert_eq!(p.list(b"(a b c)").unwrap_err().kind(), ErrorKind::TooManyMembers);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).
RFC 9110 parameters read under DuplicatePolicy::Refuse stop at
MAX_CHECKED_PARAMS (64) whatever
this says: the repeat check keeps their names on the stack (D-072).
§Examples
use parse_net::{param, ErrorKind, Limits};
let one = Limits::DEFAULT.max_params(1);
assert_eq!(param::parse(b";a=1", &one)?.0.len(), 1);
assert_eq!(param::parse(b";a=1;b=2", &one).unwrap_err().kind(), ErrorKind::TooManyMembers);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).
§Examples
use parse_net::{sfv::Parser, ErrorKind, Limits};
let p = Parser::new(Limits::DEFAULT.max_dictionary_members(1));
assert!(p.dictionary(b"a=1").is_ok());
assert_eq!(p.dictionary(b"a=1, b=2").unwrap_err().kind(), ErrorKind::TooManyMembers);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).
§Examples
use parse_net::{sfv::Parser, ErrorKind, Limits};
let p = Parser::new(Limits::DEFAULT.max_key_len(3));
assert!(p.dictionary(b"abc=1").is_ok());
assert_eq!(p.dictionary(b"abcd=1").unwrap_err().kind(), ErrorKind::TooLong);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).
§Examples
use parse_net::{sfv::Parser, ErrorKind, Limits};
let p = Parser::new(Limits::DEFAULT.max_string_len(3));
assert!(p.item(b"\"a\\\"b\"").is_ok());
assert_eq!(p.item(b"\"abcd\"").unwrap_err().kind(), ErrorKind::TooLong);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).
§Examples
use parse_net::{sfv::Parser, ErrorKind, Limits};
let p = Parser::new(Limits::DEFAULT.max_token_len(4));
assert!(p.item(b"gzip").is_ok());
assert_eq!(p.item(b"deflate").unwrap_err().kind(), ErrorKind::TooLong);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).
§Examples
use parse_net::{sfv::Parser, ErrorKind, Limits};
let p = Parser::new(Limits::DEFAULT.max_byte_seq_len(3));
assert!(p.item(b":AQID:").is_ok());
assert_eq!(p.item(b":AQIDBA==:").unwrap_err().kind(), ErrorKind::TooLong);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).
§Examples
use parse_net::{list, ErrorKind, Limits};
let one = Limits::DEFAULT.max_empty_elements(1);
assert_eq!(list::parse(b"a, , b", &one)?.len(), 2);
assert_eq!(list::parse(b"a, , , b", &one).unwrap_err().kind(), ErrorKind::TooManyEmptyElements);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).
§Examples
use parse_net::{text::parse_comment, ErrorKind, Limits};
let flat = Limits::DEFAULT.max_comment_depth(1);
assert!(parse_comment(b"(a)", &flat).is_ok());
assert_eq!(parse_comment(b"(a(b))", &flat).unwrap_err().kind(), ErrorKind::CommentTooDeep);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).
§Examples
use parse_net::{range, ByteRange, Limits, RangeOutcome};
let h = range::parse(b"bytes=0-9, 20-29", &Limits::DEFAULT)?;
let mut out = [ByteRange { start: 0, end: 0 }; 4];
assert_eq!(range::resolve(&h, 100, false, &Limits::DEFAULT, &mut out), RangeOutcome::Ranges(2));
assert_eq!(range::resolve(&h, 100, false, &Limits::DEFAULT.max_ranges(1), &mut out), RangeOutcome::Ignore);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.
§Examples
use parse_net::{mail, ErrorKind, Limits};
let two = Limits::DEFAULT.max_rfc2231_sections(2);
assert!(mail::parse_mime_params(b"; t*0=a; t*1=b", &two).is_ok());
let err = mail::parse_mime_params(b"; t*0=a; t*1=b; t*2=c", &two).unwrap_err();
assert_eq!(err.kind(), ErrorKind::TooManySections);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).
§Examples
use parse_net::{mail, ErrorKind, Limits};
let one = Limits::DEFAULT.max_encoded_words(1);
let mut buf = [0u8; 16];
assert_eq!(mail::decode_words(b"=?utf-8?q?a?=", &one, &mut buf)?, "a");
let err = mail::decode_words(b"=?utf-8?q?a?= =?utf-8?q?b?=", &one, &mut buf).unwrap_err();
assert_eq!(err.kind(), ErrorKind::TooManyMembers);Sourcepub const fn max_hops(self, n: u8) -> Self
pub const fn max_hops(self, n: u8) -> Self
The most hops in a forwarded chain (default 16).
§Examples
use parse_net::{forwarded, ErrorKind, Limits};
let lines = [&b"192.0.2.1, 198.51.100.2"[..]];
assert!(forwarded::parse_x_forwarded_for(&lines, &Limits::DEFAULT).is_ok());
let err = forwarded::parse_x_forwarded_for(&lines, &Limits::DEFAULT.max_hops(1)).unwrap_err();
assert_eq!(err.kind(), ErrorKind::TooManyHops);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.
§Examples
use parse_net::{HttpDate, Limits};
let leap = b"Sun, 06 Nov 1994 08:49:60 GMT";
assert!(HttpDate::parse_at_with(leap, 0, &Limits::DEFAULT).is_err());
let d = HttpDate::parse_at_with(leap, 0, &Limits::DEFAULT.allow_leap_second(true))?;
assert_eq!(d, HttpDate::parse_imf_fixdate(b"Sun, 06 Nov 1994 08:49:59 GMT")?);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).
§Examples
use parse_net::{param, DuplicatePolicy, Limits};
assert!(param::parse(b";a=1;a=2", &Limits::DEFAULT).is_err());
let last = Limits::DEFAULT.duplicate_params(DuplicatePolicy::Last);
let (p, _) = param::parse(b";a=1;a=2", &last)?;
assert!(p.get("a").is_some_and(|v| v.eq_bytes(b"2")));