Expand description
Minimal HTTP/1.1 server with fixed connection slots.
Reference infrastructure for the web contributor. Serves the embedded
single-file UI (web/dist), the config REST surface
(GET/POST /api/config) and hands /ws upgrades to super::ws.
Design: SLOTS long-lived tasks, each owning one [TcpSocket] for
its entire life (accept → handle → close → accept). No socket is ever
created or dropped after boot — TcpSocket::new allocates a slot from
the shared pool and re-creating sockets per connection proved fatal on
hardware (unlogged reboot). smoltcp accepts one pending connection per
listening socket, so SLOTS tasks accept SLOTS connections in
parallel; SYNs beyond that are RST and the browser retries.
Macros§
Enums§
- Outcome 🔒
- What happened to a connection after the request was read.
- Read
Error 🔒 - Why a request could not be read — drives the error response.
Constants§
- HTTP_
PORT - TCP listen port.
- REQUEST_
TIMEOUT 🔒 - Budget for reading and serving one plain request.
- RX_SIZE 🔒
- Per-slot receive buffer (headers plus a config-sized body).
- SLOTS 🔒
- Parallel connection slots. The UI is a single inlined HTML file, so a page load plus font, config fetch and WebSocket stays well below this.
- TX_SIZE 🔒
- Per-slot transmit buffer.
Statics§
- FREDOKA_
TTF 🔒 - UI font (
web/src/style.scssloads/fonts/Fredoka.ttf). - INDEX_
HTML 🔒 - Built UI (run
inv web:buildfirst —include_bytes!tracks the file).
Functions§
- content_
length 🔒 - Parsed
Content-Length(0 when absent). - find_
headers_ 🔒end - Offset of the
\r\n\r\nterminator, if present. - get_
config 🔒 GET /api/config→ full config as JSON.- parse_
body 🔒 - Body slice following the header terminator (clamped to announced length).
- parse_
request_ 🔒line - Method and path of the request line. A block without
\r\n(header-less minimal request) is treated as the line itself. - post_
config 🔒 POST /api/config→ merge patch, persist, apply; returns the status.- read_
request 🔒 - Read until
\r\n\r\nplus the announced body; returns total length. - recycle 🔒
- Close gracefully, then wait for
Closedsolisten()is legal again. - route 🔒
- Read one request and either answer it or flag the upgrade.
- send_
response 🔒 - Status + headers + body; bodies larger than the TX buffer are streamed.
- send_
status 🔒 - Status-only response (e.g. 404).
- serve 🔒
- Connection-slot loop: accept → route (or WS session) → recycle, forever.
- slot0
- HTTP connection slot 0: accept → route → recycle, permanently.
- slot1
- HTTP connection slot 1: accept → route → recycle, permanently.
- slot2
- HTTP connection slot 2: accept → route → recycle, permanently.
- slot3
- HTTP connection slot 3: accept → route → recycle, permanently.
- spawn_
all - Spawn all HTTP slots against the given stack.
- starts_
with_ 🔒ci - Case-insensitive prefix test.
- trim 🔒
- Trim ASCII whitespace/CR.
- ws_key 🔒
- Extract
Sec-WebSocket-Keyfrom the header block.