http::server
On this page
The server: an accept loop, a task per connection, HTTP/1.1 with keep-alive and pipelining, HTTP/2 over TLS (ALPN) or by prior knowledge (h2c), graceful shutdown.
Structs
ServerConfigSource
pub struct ServerConfigServer settings. Every field has a default.
Time to receive a request head once its first byte arrived.
Time a keep-alive connection may wait for its next request.
Longest wait for one read of a request body / one write.
Larger request bodies fail with
TooLarge(the connection then closes).Speak HTTP/2: offered as "h2" over TLS, by prior knowledge on plaintext connections.
HTTP/2 settings.
ServerSource
pub struct ServerA bound server. Copies share it.
Sourcepub fn bind(§addr: str, handler: Handler, cfg: ServerConfig | none = none) throws (HttpError) -> Server
Sourcepub fn bind_tls(§addr: str, handler: Handler, tls_cfg: tls::ServerConfig, cfg: ServerConfig | none = none) throws (HttpError) -> Server Accept connections until
shutdown. Runs once per server.Stop accepting, close idle connections, tell HTTP/2 connections to finish (GOAWAY), and wait for in-flight requests; after
gracethe remaining connections are cut.
Type aliases
HandlerSource
pub type Handler = fn(Request) -> AsyncFuture<Response> + Send + SyncThe request handler: one call per request, each in its own task.
Functions
serveSource
pub async fn serve(addr: str, handler: Handler) throws (HttpError) Serve handler on addr ("127.0.0.1:8080") until the process
ends.
serve_tlsSource
pub async fn serve_tls(addr: str, tls_cfg: tls::ServerConfig, handler: Handler) throws (HttpError)