Skip to main content

Module http

Module http 

Source
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§

slot_task 🔒

Enums§

Outcome 🔒
What happened to a connection after the request was read.
ReadError 🔒
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.scss loads /fonts/Fredoka.ttf).
INDEX_HTML 🔒
Built UI (run inv web:build first — include_bytes! tracks the file).

Functions§

content_length 🔒
Parsed Content-Length (0 when absent).
find_headers_end 🔒
Offset of the \r\n\r\n terminator, 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\n plus the announced body; returns total length.
recycle 🔒
Close gracefully, then wait for Closed so listen() 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-Key from the header block.