Expand description
A minimal HTTP/1.1 server, on std and nothing else.
§Why hand-rolled rather than axum
Two reasons, and the second is the real one.
The first is consistency: scema-world takes two dependencies because it is the wire
format a reimplementer has to match, and alchem-link ships a whole terminal toolkit on
the standard library for the same reason. A loopback JSON server for a known client is
squarely in that class.
The second is that pulling a full async HTTP stack into this workspace would pull
hyper → rustls/tokio, and the moment omni carries a TLS stack somebody will try to
path-depend it from the bot workspace and rediscover the zeroize/curve25519-dalek
conflict the root Cargo.toml documents at length. A server that speaks Content-Length
HTTP/1.1 to a client on the same machine does not need any of it.
§What this deliberately does not implement
Chunked transfer encoding, keep-alive, pipelining, compression, TLS, HTTP/2. Every
response closes the connection. Anything a browser or curl sends to a localhost JSON
API works; a general-purpose server this is not, and it must never be exposed to a
network — see crate::routes for the bind rule.
§Limits are enforced, not assumed
MAX_HEADER_BYTES and MAX_BODY_BYTES are checked while reading, not after. An
unbounded read from a socket is a memory exhaustion bug that looks like a hang, and the
client here can be any local process.
Structs§
Constants§
- IO_
TIMEOUT - Per-connection read/write timeout. A client that opens a socket and says nothing must not hold a slot forever.
- MAX_
BODY_ BYTES - Body cap. A
WorldStatefrom a large page is the biggest thing this carries. - MAX_
CONNECTIONS - Concurrent connections. Beyond this, new connections are accepted and immediately
answered
503rather than queued — an agent daemon that stops responding under load is worse than one that says it is busy. - MAX_
HEADER_ BYTES - Request line plus headers may not exceed this.