Skip to main content

Module media_server

Module media_server 

Source
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 — returns 200 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 in build_router.
  • The range parser (parse_range) is a pure function, independently testable, and reusable by other routes.
  • TokenRegistry is decoupled from the server; swapping the storage backend requires only changing TokenRegistryHandle.

Re-exports§

pub use tokens::TokenRegistry;
pub use tokens::TokenRegistryHandle;

Modules§

tokens
Token registry for the loopback media server.

Structs§

AppState 🔒
MediaServerHandle
Handle to the running loopback media server.

Enums§

RangeSpec
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 a RangeSpec.
range_spec_to_s3 🔒
Convert a RangeSpec into the Range header 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.