pub struct HttpServer { /* private fields */ }Expand description
A running server spawned onto the tokio runtime. Dropping the handle aborts
the accept loop (mirrors relay::RelayServer). The handler must be Send;
the interpreter’s !Send handler uses Listener/Conn directly instead.
The handle also carries the Lifecycle, so an embedder can flip readiness
(HttpServer::set_ready) and drain gracefully (HttpServer::drain)
exactly as an orchestrator’s SIGTERM handler would.
Implementations§
Source§impl HttpServer
impl HttpServer
Sourcepub fn addr(&self) -> SocketAddr
pub fn addr(&self) -> SocketAddr
The bound address (resolve :0 to its real port for clients).
Sourcepub fn set_ready(&self, ready: bool)
pub fn set_ready(&self, ready: bool)
Flip the readiness gate: false sheds new requests with 503 (a load
balancer stops routing), true serves them — independent of liveness
(the accept loop stays up either way).
Sourcepub fn is_ready(&self) -> bool
pub fn is_ready(&self) -> bool
Whether the server is currently serving (ready and not draining).
Sourcepub async fn drain(&self, deadline: Duration) -> DrainOutcome
pub async fn drain(&self, deadline: Duration) -> DrainOutcome
Gracefully drain: stop accepting new connections (new requests shed with
503), wait up to deadline for in-flight requests to finish, and
return the still-running count as DrainOutcome::dropped (0 = every
in-flight request completed). Never hangs past deadline.