#[non_exhaustive]pub struct ServeConfig {
pub max_connections: Option<usize>,
pub drain_timeout: Duration,
pub header_read_timeout: Option<Duration>,
pub idle_timeout: Option<Duration>,
}Expand description
Limits applied to a Server.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.max_connections: Option<usize>Ceiling on connections being served at once. None is unbounded, which
is serve’s behaviour and is kept as an explicit choice
rather than a default.
The permit is taken before accept(), so the ceiling is on accepted
sockets. Load past it queues in the listen backlog and is refused by the
kernel when that fills — which is a far better failure than an
unbounded task spawn that turns a traffic spike into an OOM.
drain_timeout: DurationHow long to wait for watched connections to finish after shutdown is signalled, before giving up and reporting them abandoned.
header_read_timeout: Option<Duration>How long a peer may take to send complete request headers. None
disables the check.
This is the slowloris defence: a connection dribbling headers a byte at a time is refused instead of holding a task indefinitely.
idle_timeout: Option<Duration>How long a connection may go with no traffic in either direction before
it is closed. None disables the check.
Covers what the header timeout cannot: a peer that sent its headers promptly and then stopped mid-body, or one that finished a request and kept the connection open doing nothing.
Implementations§
Source§impl ServeConfig
impl ServeConfig
Sourcepub fn new() -> Self
pub fn new() -> Self
The defaults: unbounded connections, DEFAULT_DRAIN_TIMEOUT,
DEFAULT_HEADER_READ_TIMEOUT and DEFAULT_IDLE_TIMEOUT.
Both timeouts default to on. An unbounded connection is the kind of default that only looks harmless until someone points a slowloris at it, and this constructor is new enough to have no callers relying on the permissive behaviour.
Sourcepub const fn with_max_connections(self, max: usize) -> Self
pub const fn with_max_connections(self, max: usize) -> Self
Caps the connections served at once.
This type is #[non_exhaustive] — a header-read timeout and an idle
timeout are the obvious next fields — so it is built with setters rather
than a struct literal, and gaining one of those is not a breaking
change.
Sourcepub const fn with_drain_timeout(self, timeout: Duration) -> Self
pub const fn with_drain_timeout(self, timeout: Duration) -> Self
Sets how long shutdown waits for in-flight connections.
Sourcepub const fn with_header_read_timeout(self, timeout: Option<Duration>) -> Self
pub const fn with_header_read_timeout(self, timeout: Option<Duration>) -> Self
Sets how long a peer may take to send complete request headers.
None disables it. Do that only behind a proxy that already enforces
one — this is the check that makes a slowloris cost the attacker
something.
Sourcepub const fn with_idle_timeout(self, timeout: Option<Duration>) -> Self
pub const fn with_idle_timeout(self, timeout: Option<Duration>) -> Self
Sets how long a connection may go with no traffic before it is closed.
None disables it. Raise it rather than disabling it if a deployment
streams responses with long quiet stretches, and keep it above the SSE
keep-alive interval — see DEFAULT_IDLE_TIMEOUT.
Trait Implementations§
Source§impl Clone for ServeConfig
impl Clone for ServeConfig
Source§fn clone(&self) -> ServeConfig
fn clone(&self) -> ServeConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ServeConfig
impl Debug for ServeConfig
Auto Trait Implementations§
impl Freeze for ServeConfig
impl RefUnwindSafe for ServeConfig
impl Send for ServeConfig
impl Sync for ServeConfig
impl Unpin for ServeConfig
impl UnsafeUnpin for ServeConfig
impl UnwindSafe for ServeConfig
Blanket Implementations§
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> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request