ulo-http-hyper
The reference HTTP server, built on hyper, with its settings, defaults and limits.
ulo-http-hyper is the server crate every example uses unless it says otherwise. It accepts connections itself, serves HTTP/1.1 and HTTP/2 through hyper, and hands each request to ulo-http's router.
use ulo_http_hyper::Server;
app.bind(Server::new("127.0.0.1:3000"))Server is ulo_http::Server over hyper on tokio's sockets. The default tokio feature selects that listener. With the feature off, ServerOn<L> serves on a listener a runtime crate names, and no tokio runtime crate is built; see Runtimes.
Endpoints
Server::new takes text ("0.0.0.0:8080"), a SocketAddr or an ulo_net::Endpoint. Text is parsed when the app listens, so main carries no ? for it. .endpoint(..) adds more endpoints to the same server.
- Port 0 binds a port the OS chooses.
app.addresses()reports it afterlisten. Endpoint::inherited("http")andEndpoint::inherited_index(0)adopt a socket passed by a supervisor throughLISTEN_FDS, matched byLISTEN_FDNAMESfor the named form. The descriptor is accepted only whenLISTEN_PIDequals the process ID, and it must be a listening stream socket.- A server that binds several endpoints is all-or-nothing: if one fails to bind, the ones already open are closed.
Settings
Each setting is a builder method on the server. Defaults are read from ulo-http's HttpConfig.
| Method | Default | Effect |
|---|---|---|
tls(Tls) | none | HTTPS on every endpoint. See TLS. |
max_body(bytes) | 2 MiB | Request body cap of a route without #[meta(MaxBody(..))]. |
max_inflight(Count) | 1,024 requests | Over it a request is answered 503 with Retry-After. |
shed_retry_after(Duration) | 1 second | The Retry-After of a shed or draining refusal. |
max_concurrent_streams(Count) | hyper's own | HTTP/2 SETTINGS_MAX_CONCURRENT_STREAMS per connection. |
h2c(bool) | false | HTTP/2 without TLS. |
header_timeout(Bound) | 30 seconds | Time for a request head to arrive. HTTP/1.1 only. |
handshake_timeout(Bound) | 30 seconds | Time for a TLS handshake. |
timeout_grace(Bound) | 1 second | How long error handlers have after a route timeout before a 504 is sent. |
challenge(..) | Bearer | The WWW-Authenticate value of a 401 whose error names none. |
Count is Default, Max(n) or Unlimited, and a timeout is a Bound: Default, After(d) or Unbounded. No setting is an Option, so "the default" and "no limit" stay distinct.
A setting that would refuse everything it governs fails listen as Configure: a zero header_timeout, handshake_timeout or timeout_grace, and Count::Max(0) on max_inflight or max_concurrent_streams. The error text names the replacement (Bound::Unbounded, Count::Unlimited).
Limits and quirks
ulo-http-hyper declares no limits: ports, TLS, h2c, inherited sockets and per-request upgrades all work. Three behaviours are specific to it:
header_timeoutis hyper's HTTP/1.1 header-read timeout. An HTTP/2 connection has no head-read clock.max_concurrent_streamsatCount::Defaultsends hyper's own value, which hyper does not hold stable between releases.Bound::Unboundedonheader_timeoutorhandshake_timeoutlets a peer hold a connection open until the drain's deadline.
Shutdown
At the drain the server stops accepting, sends HTTP/2 GOAWAY, closes idle HTTP/1.1 keep-alive connections and marks busy ones Connection: close on their next response. SSE handlers see draining() and end their streams. A request that still arrives after the drain began is answered 503 with Retry-After and Connection: close, and the pre-dispatch stage does not run for it. The window is AppBuilder::drain_timeout, ten seconds unset.
A peer that closes the connection or resets the stream cancels the execution with Disconnected, before the response's head is produced as well as before its body ends.