Skip to main content

Module server

Module server 

Source
Expand description

The listeners and connection loops.

Server::setup binds the listener (and, in the http1 build, creates the thread pool); then Server::run (http1), run_tls (TLS with HTTP/2 via ALPN, or plain HTTP/1.1 without a certificate), run_quic (HTTP/3) and run_redirect (HTTP → HTTPS) accept connections, parse requests and hand them to your Application. ConnectionInfo carries the client and server addresses and the TLS SNI name. Examples: src/server/example/.

Modules§

per_core
Per-core runtimes (RWS_CONFIG_RUNTIME=per-core, Unix only): one single-threaded tokio runtime per core, each accepting on its own SO_REUSEPORT socket, the way nginx runs one worker per core. A connection stays on the thread the kernel gave it to, so there’s no work stealing, no cross-thread wake-ups and no idle workers searching for work.
proxy_protocol
Inbound PROXY protocol, versions 1 (text) and 2 (binary), as HAProxy, AWS NLB, GCP and most L4 load balancers send it: the client’s address, prepended to the connection. With proxy_protocol = true (RWS_CONFIG_PROXY_PROTOCOL) every connection to the main listener must start with one — before the TLS handshake on HTTPS — and its source address becomes the client address rws logs, rate-limits and forwards in X-Forwarded-For. A connection without a valid header is closed.

Structs§

Address
IP address and port pair.
ConnectionInfo
Network context for the current connection, passed into every Controller.
Server

Constants§

REQUEST_HEAD_TIMEOUT
Longest time from the first byte of a request head to its end (nginx’s client_header_timeout). The idle timeout alone restarts on every read, so a client sending one byte every few seconds could hold a connection for weeks with a 64 KiB head.

Functions§

request_shutdown
Shut the server down gracefully, as SIGTERM does — for hosts that stop a process some other way (a Windows service’s Stop control). The accept loops of run_tls, run_plain, run_quic and run_redirect end.