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 = 60000Fields§
§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: u64How long a client has to answer an HTTP/2 ping before the connection closes (default 20 s).
http2_max_concurrent_streams: u32The 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: usizeThe 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: usizeThe 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.