pub struct Limits { /* private fields */ }Expand description
The budgets a connection enforces on incoming messages.
Every limit is checked before the bytes it governs are buffered or
allocated: a declared Content-Length above max_body
is refused on the header line, a chunk size is checked against the
remaining body budget before its data is read, and the connection’s input
buffer can never grow past 2 * (max_start_line + max_header_bytes) plus a
fixed 16 KiB body window (64 KiB with the defaults): room for a pinned
head plus one partial chunk line or trailer section.
The defaults are the budgets of LexerSketch Studio’s localhost server:
| Budget | Default |
|---|---|
| request line / status line / chunk-size line | 8 KiB |
| header section (all field lines) | 16 KiB |
| header fields (and, separately, trailer fields) | 100 |
| body | 1 MiB |
§Examples
use http_net::Limits;
let limits = Limits::new().with_max_body(64 * 1024).with_max_headers(32);
assert_eq!(limits.max_body(), 64 * 1024);
assert_eq!(limits.max_headers(), 32);
assert_eq!(limits.max_start_line(), 8 * 1024);Implementations§
Source§impl Limits
impl Limits
Sourcepub const fn with_max_start_line(self, bytes: usize) -> Self
pub const fn with_max_start_line(self, bytes: usize) -> Self
Sets the longest accepted request line, status line, or chunk-size
line, in bytes including the CRLF. Clamped to 16..=16 MiB.
§Examples
let l = http_net::Limits::new().with_max_start_line(1);
assert_eq!(l.max_start_line(), 16);Sourcepub const fn with_max_header_bytes(self, bytes: usize) -> Self
pub const fn with_max_header_bytes(self, bytes: usize) -> Self
Sets the largest accepted header section (every field line plus the
blank line that ends it), in bytes. Clamped to 2..=16 MiB.
§Examples
let l = http_net::Limits::new().with_max_header_bytes(4096);
assert_eq!(l.max_header_bytes(), 4096);Sourcepub const fn with_max_headers(self, count: usize) -> Self
pub const fn with_max_headers(self, count: usize) -> Self
Sets the most header fields accepted in one message (trailer fields
are counted against the same number separately). Clamped to
0..=65536.
§Examples
let l = http_net::Limits::new().with_max_headers(8);
assert_eq!(l.max_headers(), 8);Sourcepub const fn with_max_body(self, bytes: u64) -> Self
pub const fn with_max_body(self, bytes: u64) -> Self
Sets the largest accepted body, in bytes after chunked decoding.
§Examples
let l = http_net::Limits::new().with_max_body(0);
assert_eq!(l.max_body(), 0);Sourcepub const fn max_start_line(&self) -> usize
pub const fn max_start_line(&self) -> usize
The longest accepted start line or chunk-size line, CRLF included.
§Examples
assert_eq!(http_net::Limits::new().max_start_line(), 8192);Sourcepub const fn max_header_bytes(&self) -> usize
pub const fn max_header_bytes(&self) -> usize
The largest accepted header section, in bytes.
§Examples
assert_eq!(http_net::Limits::new().max_header_bytes(), 16384);Sourcepub const fn max_headers(&self) -> usize
pub const fn max_headers(&self) -> usize
The most header fields accepted in one message.
§Examples
assert_eq!(http_net::Limits::new().max_headers(), 100);Sourcepub const fn max_body(&self) -> u64
pub const fn max_body(&self) -> u64
The largest accepted body, in bytes.
§Examples
assert_eq!(http_net::Limits::new().max_body(), 1 << 20);Sourcepub const fn buffer_capacity(&self) -> usize
pub const fn buffer_capacity(&self) -> usize
The input buffer’s hard capacity, 2 * (max_start_line + max_header_bytes) + 16 KiB (64 KiB with the defaults), so a driver
can plan memory per connection.
The current message’s head stays pinned while its body streams, and
the decoder may need one whole chunk-size line or trailer section on
top of it, so twice the head budget plus the body window always fits
whatever the parser is waiting to complete. A connection’s memory is
this buffer plus max_headers field records of 16 bytes each.
§Examples
use http_net::Limits;
assert_eq!(Limits::new().buffer_capacity(), 64 * 1024);
let small = Limits::new().with_max_start_line(1024).with_max_header_bytes(4096);
assert_eq!(small.buffer_capacity(), 2 * (1024 + 4096) + 16 * 1024);