ulo
ulo
Documentation

Start here

Coming from NestJSNestJS topics, mapped

The model

Protocols

HTTP Serversulo-http-hyperTLSRuntimesEmbeddingaxumactix-websalvopoemrocketWriting a server crate

Integrations

Operating

Reference

HTTP Servers

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 after listen.
  • Endpoint::inherited("http") and Endpoint::inherited_index(0) adopt a socket passed by a supervisor through LISTEN_FDS, matched by LISTEN_FDNAMES for the named form. The descriptor is accepted only when LISTEN_PID equals 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.

MethodDefaultEffect
tls(Tls)noneHTTPS on every endpoint. See TLS.
max_body(bytes)2 MiBRequest body cap of a route without #[meta(MaxBody(..))].
max_inflight(Count)1,024 requestsOver it a request is answered 503 with Retry-After.
shed_retry_after(Duration)1 secondThe Retry-After of a shed or draining refusal.
max_concurrent_streams(Count)hyper's ownHTTP/2 SETTINGS_MAX_CONCURRENT_STREAMS per connection.
h2c(bool)falseHTTP/2 without TLS.
header_timeout(Bound)30 secondsTime for a request head to arrive. HTTP/1.1 only.
handshake_timeout(Bound)30 secondsTime for a TLS handshake.
timeout_grace(Bound)1 secondHow long error handlers have after a route timeout before a 504 is sent.
challenge(..)BearerThe 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_timeout is hyper's HTTP/1.1 header-read timeout. An HTTP/2 connection has no head-read clock.
  • max_concurrent_streams at Count::Default sends hyper's own value, which hyper does not hold stable between releases.
  • Bound::Unbounded on header_timeout or handshake_timeout lets 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.

HTTP Servers

The two ways to serve an Ulo application over HTTP, a server crate that owns the sockets or a host framework that does, and how to choose between them.

TLS

Serving HTTPS from a PEM certificate chain and key, or from a rustls configuration of your own.

On this page

EndpointsSettingsLimits and quirksShutdown