Skip to main content

serve_tls

Function serve_tls 

Source
pub async fn serve_tls(
    listener: TcpListener,
    router: Router,
    config: Arc<ServerConfig>,
) -> Result<()>
Expand description

Serves an already-built router on listener, terminating TLS with config, until SIGINT or SIGTERM, on the same SHUTDOWN_GRACE serve_router gives the plain-HTTP path.

config is expected to come from didbot_tls::manager::CertificateManager ::server_config, or anything else built the same way: one rustls::ServerConfig for the whole life of this call, whose certificate resolver is itself swappable. A renewal happening elsewhere replaces what that resolver hands back; it does not call this function again, does not rebind listener, and does not touch a connection already past its handshake — the certificate only ever participates in the handshake that created a connection. This crate does not know how to renew a certificate, and does not need to: it only needs one ServerConfig that keeps answering correctly for as long as the process runs.

This is why serve_tls takes a config rather than, say, a certificate path: baking “reload the files and rebuild the config” in here would put the rebind-avoidance property back in the caller’s hands, exactly where the epic that asked for this said it must not be.

Served through limited_make_service, the wrapping serve_router serves through, so MAX_CONCURRENT_REQUESTS bounds this listener’s in-flight requests the same way, and with HEADER_READ_TIMEOUT on the reading of a request’s headers.