Skip to main content

ServerLimits

Struct ServerLimits 

Source
pub struct ServerLimits { /* private fields */ }
Expand description

Wire-level resource limits for the native protocol adapters.

These limits are enforced before an operation is dispatched. They therefore protect every application independently of its extractors or business code. Header/body limits apply to both protocols; chunk and keep-alive request counts are HTTP/1-specific, while concurrent streams are HTTP/2-specific. The socket deadlines bound a peer that opens a connection and then stops making progress.

Implementations§

Source§

impl ServerLimits

Source

pub const fn new() -> Self

Source

pub const fn with_max_header_bytes(self, bytes: usize) -> Self

Source

pub const fn with_max_headers(self, count: usize) -> Self

Sets the maximum header count.

The native parser keeps its header slots on the stack, so this value is capped at 128 instead of allocating once per request.

Source

pub const fn with_max_body_bytes(self, bytes: usize) -> Self

Source

pub const fn with_max_chunks(self, count: usize) -> Self

Limits the number of chunks in one chunked HTTP/1 request.

Source

pub const fn with_max_pipeline_batch(self, count: NonZeroUsize) -> Self

Bounds the number of pipelined HTTP/1 responses coalesced into one socket write. A value of one disables response coalescing.

Source

pub const fn with_max_requests_per_connection( self, count: Option<NonZeroUsize>, ) -> Self

Bounds keep-alive reuse. None allows requests until either peer closes.

Source

pub const fn with_stream_read_bytes(self, bytes: usize) -> Self

Sets the read window for streaming request bodies.

A streamed upload travels as owned chunks of at most this many bytes, and each chunk costs one read, one pass through the body channel, and one wakeup of the consuming handler. The window therefore trades a bounded amount of per-upload memory — at most a handful of windows is ever in flight for one request — against per-chunk overhead. The default of 64 KiB moves a five-megabyte upload in eighty chunks where the 8 KiB connection buffer would take six hundred forty, for tens of kilobytes of look-ahead per in-flight upload.

The body channel’s queue limit scales with this window, so enlarging it never strangles the producer against a fixed queue.

Source

pub const fn with_header_read_timeout(self, timeout: Duration) -> Self

Bounds how long a complete request head may take to arrive once its first byte has been buffered.

Source

pub const fn with_body_read_timeout(self, timeout: Duration) -> Self

Bounds how long one request-body read may stall.

Source

pub const fn with_idle_timeout(self, timeout: Duration) -> Self

Bounds how long an idle keep-alive connection may wait for the first byte of its next request.

Source

pub const fn with_write_timeout(self, timeout: Duration) -> Self

Bounds how long one response write may stall.

Source

pub const fn max_header_bytes(self) -> usize

Source

pub const fn max_headers(self) -> usize

Source

pub const fn max_body_bytes(self) -> usize

Source

pub const fn max_chunks(self) -> usize

Source

pub const fn max_pipeline_batch(self) -> usize

Source

pub const fn max_requests_per_connection(self) -> Option<NonZeroUsize>

Source

pub const fn stream_read_bytes(self) -> usize

Source

pub const fn header_read_timeout(self) -> Duration

Source

pub const fn body_read_timeout(self) -> Duration

Source

pub const fn idle_timeout(self) -> Duration

Source

pub const fn write_timeout(self) -> Duration

Trait Implementations§

Source§

impl Clone for ServerLimits

Source§

fn clone(&self) -> ServerLimits

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 ServerLimits

Source§

impl Debug for ServerLimits

Source§

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

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

impl Default for ServerLimits

Source§

fn default() -> Self

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

impl Eq for ServerLimits

Source§

impl PartialEq for ServerLimits

Source§

fn eq(&self, other: &ServerLimits) -> 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 ServerLimits

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> BackgroundExt for T

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ResponseExt for T

Source§

fn header( self, name: impl Into<String>, value: impl Into<String>, ) -> WithHeaders<Self>

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more