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 |
| one field line (headers and trailers) | 8 KiB |
| header fields | 100 |
| trailer section, trailer fields | the header budgets |
| interim (1xx) responses per request (client) | 16 |
| 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_field_line(self, bytes: usize) -> Self
pub const fn with_max_field_line(self, bytes: usize) -> Self
Sets the longest accepted single field line (name, colon, value, and
CRLF), in headers and trailers alike. Clamped to 4..=16 MiB. A line
over it is HttpError::FieldLineTooLong
(431), checked before the rest of the line is buffered. The whole
section is still bounded by
max_header_bytes.
§Examples
let l = http_net::Limits::new().with_max_field_line(1024);
assert_eq!(l.max_field_line(), 1024);Sourcepub const fn with_max_trailer_bytes(self, bytes: usize) -> Self
pub const fn with_max_trailer_bytes(self, bytes: usize) -> Self
Sets the largest accepted trailer section, in bytes (every trailer
field line plus the blank line that ends it). Clamped to
2..=16 MiB. Until it is set it follows
max_header_bytes.
§Examples
let l = http_net::Limits::new().with_max_trailer_bytes(512);
assert_eq!(l.max_trailer_bytes(), 512);
assert_eq!(http_net::Limits::new().max_trailer_bytes(), 16 * 1024);Sourcepub const fn with_max_trailer_fields(self, count: usize) -> Self
pub const fn with_max_trailer_fields(self, count: usize) -> Self
Sets the most trailer fields accepted in one message. Clamped to
0..=65536. Until it is set it follows
max_headers.
§Examples
let l = http_net::Limits::new().with_max_trailer_fields(4);
assert_eq!(l.max_trailer_fields(), 4);Sourcepub const fn with_max_interim(self, count: u16) -> Self
pub const fn with_max_interim(self, count: u16) -> Self
Sets the most interim (1xx) responses a client accepts before the
final response to one request; one more is
HttpError::TooManyInterim. The
interim heads together also count against
max_header_bytes.
§Examples
let l = http_net::Limits::new().with_max_interim(2);
assert_eq!(l.max_interim(), 2);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_field_line(&self) -> usize
pub const fn max_field_line(&self) -> usize
The longest accepted single field line, CRLF included.
§Examples
assert_eq!(http_net::Limits::new().max_field_line(), 8192);Sourcepub const fn max_trailer_bytes(&self) -> usize
pub const fn max_trailer_bytes(&self) -> usize
The largest accepted trailer section, in bytes.
§Examples
let l = http_net::Limits::new().with_max_header_bytes(4096);
assert_eq!(l.max_trailer_bytes(), 4096);Sourcepub const fn max_trailer_fields(&self) -> usize
pub const fn max_trailer_fields(&self) -> usize
The most trailer fields accepted in one message.
§Examples
assert_eq!(http_net::Limits::new().max_trailer_fields(), 100);Sourcepub const fn max_interim(&self) -> u16
pub const fn max_interim(&self) -> u16
The most interim responses a client accepts per request.
§Examples
assert_eq!(http_net::Limits::new().max_interim(), 16);Sourcepub const fn with_pipeline_depth(self, depth: u8) -> Self
pub const fn with_pipeline_depth(self, depth: u8) -> Self
Sets how many requests a client may have outstanding at once
(pipelining, RFC 9112 section 9.3.2). Clamped to 1..=32; 1 (the
default) means one request at a time. Only idempotent requests with
full bodies are pipelined; see
ClientConn::can_send.
§Examples
let l = http_net::Limits::new().with_pipeline_depth(8);
assert_eq!(l.pipeline_depth(), 8);
assert_eq!(http_net::Limits::new().with_pipeline_depth(0).pipeline_depth(), 1);
assert_eq!(http_net::Limits::new().with_pipeline_depth(200).pipeline_depth(), 32);Sourcepub const fn pipeline_depth(&self) -> u8
pub const fn pipeline_depth(&self) -> u8
How many requests a client may have outstanding at once.
§Examples
assert_eq!(http_net::Limits::new().pipeline_depth(), 1);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, head + max(head, max_trailer_bytes) + 16 KiB where head = max_start_line + max_header_bytes (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 this 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 (and as many for trailers when they
are reported).
§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);