Skip to main content

ServerOptions

Struct ServerOptions 

Source
pub struct ServerOptions {
Show 13 fields pub header_read_timeout_ms: Option<u64>, pub idle_timeout_ms: Option<u64>, pub body_read_timeout_ms: Option<u64>, pub body_min_bytes_per_sec: Option<u64>, pub http2_keep_alive_interval_ms: Option<u64>, pub http2_keep_alive_timeout_ms: u64, pub http2_max_concurrent_streams: u32, pub max_connections: Option<usize>, pub max_connections_per_ip: Option<usize>, pub max_header_bytes: usize, pub max_headers: usize, pub write_stall_timeout_ms: Option<u64>, pub upgraded_idle_timeout_ms: Option<u64>,
}
Expand description

The limits on connections, enforced by serve on every listener (configuration section http.server; every key optional). They bound what a client can hold without finishing anything, and the defaults are meant for production.

A key of type Option is turned off with None, which TOML cannot write (set it to null through ConfigSources, or in code, as for http.per_ip_rate_limit); 0 fails the boot.

[http.server]
header_read_timeout_ms = 10000
idle_timeout_ms = 75000
body_read_timeout_ms = 20000
body_min_bytes_per_sec = 256
http2_keep_alive_interval_ms = 30000
http2_keep_alive_timeout_ms = 20000
http2_max_concurrent_streams = 200
max_connections = 10000
max_connections_per_ip = 256
max_header_bytes = 32768
max_headers = 100
write_stall_timeout_ms = 60000

Fields§

§header_read_timeout_ms: Option<u64>

How long a client has to send a request head, from the moment it connects (or from its first byte, between two requests of a connection) to the end of the head (default 10 s). A client that takes longer, however steadily it sends, is disconnected. On HTTP/2 a new connection has this long to open its first stream. A head sent in one read with a request that has no body is timed from the end of that response; after a request with a body it has idle_timeout_ms.

§idle_timeout_ms: Option<u64>

How long a connection may sit with no request in flight before the server closes it (default 75 s, above the 60 s of common load balancers, so they close first and never reuse a closing connection). Nothing a client sends extends it on HTTP/2; on HTTP/1 its next byte starts a request head, and with header_read_timeout_ms off this deadline stays. A response still on its way to the client is not idle: write_stall_timeout_ms is the limit then.

§body_read_timeout_ms: Option<u64>

The longest the server waits for a request body while a handler reads it (default 20 s): a stall this long ends the read with a 408, and the connection closes (on HTTP/2 the stream ends and the connection stays). Only time spent waiting on the client counts.

§body_min_bytes_per_sec: Option<u64>

The slowest a request body may arrive, averaged over time (default 256 bytes per second): each byte earns back 1 / rate seconds of body_read_timeout_ms, so a client dripping bytes runs out of it even though it never stalls for long. None makes any byte restore the whole timeout. Does nothing without body_read_timeout_ms.

§http2_keep_alive_interval_ms: Option<u64>

How often an HTTP/2 connection that has gone quiet is pinged (default 30 s), so dead peers are found while a request is in flight.

§http2_keep_alive_timeout_ms: u64

How long a client has to answer an HTTP/2 ping before the connection closes (default 20 s).

§http2_max_concurrent_streams: u32

The most requests one HTTP/2 connection may have open at once (default 200).

§max_connections: Option<usize>

The most connections open at once, WebSockets and TLS handshakes in progress included (default 10 000). At the cap new connections wait until one closes, nearly all of them in the listen backlog, and nothing is read from or answered on them until then. For a client that has sent something, the connection idle the longest closes, as at its idle timeout, one for each such client, and a connection that has only started its next request head counts as idle. A client that has sent nothing closes nothing, and has header_read_timeout_ms to wait.

§max_connections_per_ip: Option<usize>

The most connections open at once from one client address (default 256), counted like http.per_ip_rate_limit: per IPv4 address, or per IPv6 network of http.rate_limit_ipv6_prefix bits. At the limit a new connection takes the place of the address’s own connection idle the longest, closed as at its idle timeout. That one counts until its socket has closed, and at most 8 of an address’s connections (no more than the limit) close for newer ones at a time, so one address holds at most the limit and those. When none of its connections is idle, or that many are closing, the new one is closed at once; it cannot wait, because the address is only known after the accept.

This limits what one address can hold. It does not stop a client with many addresses, which max_connections is then the limit for.

Peers in http.trusted_proxies, or every peer with http.trust_proxy, are not counted: each carries many clients. Behind a reverse proxy list it there (http.per_ip_rate_limit needs that too) or raise this, or a busy proxy runs into it. So can many clients sharing one address, such as an office or a carrier.

Counted per listener, like max_connections, and by the peer of the socket, so a proxy’s clients are never limited here: limit those at the proxy.

§max_header_bytes: usize

The largest request head, in bytes (default 32 KiB, at least 8 KiB): the request line and headers on HTTP/1, the header list on HTTP/2, where each header also counts 32 bytes. Above it the answer is a 431.

§max_headers: usize

The most headers a request may have (default 100, 431 above it). On HTTP/2 a header can cost a client a single byte, so without this a small request could carry a thousand into the app; a browser’s cookies can count one each there, as HTTP/2 allows sending them apart.

§write_stall_timeout_ms: Option<u64>

How long a response may go without moving (default 60 s). When the socket takes nothing for this long the connection closes; when an HTTP/2 client’s flow control holds one response back for this long, that stream is reset and the connection stays. Each byte the socket takes starts it over, and on HTTP/2 each 16 KiB the client takes from a response, so only a client that has really stopped runs out. It also applies to what a handler writes to an upgraded HTTP/1 socket, but not to an HTTP/2 WebSocket held back by flow control: that is the work of upgraded_idle_timeout_ms, or of a timeout on the handler’s own writes. A client pausing a large download for longer loses it and has to ask for the rest.

§upgraded_idle_timeout_ms: Option<u64>

How long an upgraded connection (a WebSocket) may go with no bytes from its client before it closes (default None: never). A quiet WebSocket is a healthy one to the server, so this is for apps that know how their sockets talk: set it above the heartbeat of the protocol, whose answers are what count. What the server writes does not, so a heartbeat of its own cannot keep a silent client’s socket open. The connection closes with an error, so a handler sees its read fail, and a handler must be reading for this to work. On HTTP/2 it applies once nothing but upgraded streams is left on the connection, and only DATA counts: the frames that look after the connection, such as keep-alive pings, are silence.

Trait Implementations§

Source§

impl Clone for ServerOptions

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 ConfigTable for ServerOptions

Source§

fn fields() -> Vec<FieldSchema>

The fields, in the order they are declared.
Source§

fn to_json(&self) -> Value

The value as JSON, field by field, for the defaults: credentials are null, a value of a type the description does not know is its Debug text.
Source§

impl Debug for ServerOptions

Source§

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

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

impl Default for ServerOptions

Source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for ServerOptions

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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> 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 = !

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