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
impl ServerLimits
pub const fn new() -> Self
pub const fn with_max_header_bytes(self, bytes: usize) -> Self
Sourcepub const fn with_max_headers(self, count: usize) -> Self
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.
pub const fn with_max_body_bytes(self, bytes: usize) -> Self
Sourcepub const fn with_max_chunks(self, count: usize) -> Self
pub const fn with_max_chunks(self, count: usize) -> Self
Limits the number of chunks in one chunked HTTP/1 request.
Sourcepub const fn with_max_pipeline_batch(self, count: NonZeroUsize) -> Self
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.
Sourcepub const fn with_max_requests_per_connection(
self,
count: Option<NonZeroUsize>,
) -> Self
pub const fn with_max_requests_per_connection( self, count: Option<NonZeroUsize>, ) -> Self
Bounds keep-alive reuse. None allows requests until either peer closes.
Sourcepub const fn with_stream_read_bytes(self, bytes: usize) -> Self
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.
Sourcepub const fn with_header_read_timeout(self, timeout: Duration) -> Self
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.
Sourcepub const fn with_body_read_timeout(self, timeout: Duration) -> Self
pub const fn with_body_read_timeout(self, timeout: Duration) -> Self
Bounds how long one request-body read may stall.
Sourcepub const fn with_idle_timeout(self, timeout: Duration) -> Self
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.
Sourcepub const fn with_write_timeout(self, timeout: Duration) -> Self
pub const fn with_write_timeout(self, timeout: Duration) -> Self
Bounds how long one response write may stall.
pub const fn max_header_bytes(self) -> usize
pub const fn max_headers(self) -> usize
pub const fn max_body_bytes(self) -> usize
pub const fn max_chunks(self) -> usize
pub const fn max_pipeline_batch(self) -> usize
pub const fn max_requests_per_connection(self) -> Option<NonZeroUsize>
pub const fn stream_read_bytes(self) -> usize
pub const fn header_read_timeout(self) -> Duration
pub const fn body_read_timeout(self) -> Duration
pub const fn idle_timeout(self) -> Duration
pub const fn write_timeout(self) -> Duration
Trait Implementations§
Source§impl Clone for ServerLimits
impl Clone for ServerLimits
Source§fn clone(&self) -> ServerLimits
fn clone(&self) -> ServerLimits
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for ServerLimits
Source§impl Debug for ServerLimits
impl Debug for ServerLimits
Source§impl Default for ServerLimits
impl Default for ServerLimits
impl Eq for ServerLimits
Source§impl PartialEq for ServerLimits
impl PartialEq for ServerLimits
impl StructuralPartialEq for ServerLimits
Auto Trait Implementations§
impl Freeze for ServerLimits
impl RefUnwindSafe for ServerLimits
impl Send for ServerLimits
impl Sync for ServerLimits
impl Unpin for ServerLimits
impl UnsafeUnpin for ServerLimits
impl UnwindSafe for ServerLimits
Blanket Implementations§
Source§impl<T> BackgroundExt for T
impl<T> BackgroundExt for T
fn background(self, task: BackgroundTask) -> Background<Self>
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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