Expand description
Loopback media server — streams S3 objects over http://127.0.0.1:<port>.
§Overview
At app start, start_on_localhost spawns an axum HTTP server bound to
127.0.0.1:0 (OS-assigned port). The caller receives a
MediaServerHandle that carries the port, the shared
TokenRegistryHandle, and a shutdown sender.
The server exposes two routes:
GET /m/:token— validates the token, streams the S3 object (with optional byte-range support so video<seek>works).GET /healthz— returns200 OK; used by diagnostics and tests.
§Range support
The server forwards an Range: bytes=START-END header to the S3
get_object call and returns a 206 Partial Content response with the
matching Content-Range header.
§OCP
- Adding a new route is one
.route(...)call inbuild_router. - The range parser (
parse_range) is a pure function, independently testable, and reusable by other routes. TokenRegistryis decoupled from the server; swapping the storage backend requires only changingTokenRegistryHandle.
Re-exports§
pub use tokens::TokenRegistry;pub use tokens::TokenRegistryHandle;
Modules§
- tokens
- Token registry for the loopback media server.
Structs§
- AppState 🔒
- Media
Server Handle - Handle to the running loopback media server.
Enums§
- Range
Spec - A parsed byte range from an HTTP
Range: bytes=…header.
Functions§
- build_
router 🔒 - healthz 🔒
GET /healthz— returns 200 OK for diagnostics.- parse_
range - Parse
Range: bytes=<spec>into aRangeSpec. - range_
spec_ 🔒to_ s3 - Convert a
RangeSpecinto theRangeheader value forwarded to S3. - serve_
media 🔒 GET /m/:token— validate token and stream the S3 object.- start_
on_ localhost - Start the loopback media server and return a
MediaServerHandle.