Skip to main content

Limits

Struct Limits 

Source
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:

BudgetDefault
request line / status line / chunk-size line8 KiB
header section (all field lines)16 KiB
header fields (and, separately, trailer fields)100
body1 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

Source

pub const fn new() -> Self

The default budgets (see the table on Limits).

§Examples
assert_eq!(http_net::Limits::new(), http_net::Limits::default());
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

pub const fn max_body(&self) -> u64

The largest accepted body, in bytes.

§Examples
assert_eq!(http_net::Limits::new().max_body(), 1 << 20);
Source

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);

Trait Implementations§

Source§

impl Clone for Limits

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Limits

Source§

impl Debug for Limits

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Limits

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for Limits

Source§

impl Hash for Limits

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Limits

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Limits

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.