moonzero · control plane v0.15.0 · 49 packages · 4 targets · Apache-2.0 docs / edge / files GitHub

06 / EDGE

files

A file-serving layer over an in-memory set: a GET under a prefix whose remaining path names a registered file is answered with it, with a content-derived ETag and a 304 for a conditional request. The bytes live in a value, so a test serves a file it built and a deployment loads a directory once.

struct FileEntry

structOne servable file: its bytes and the media type it is announced with. The ETag is derived from the content, so a conditional request works without the loader having to know a modification time.

struct Files

structThe files a service serves, keyed by path relative to the mount prefix.

fn Files::new() -> Files

fnAn empty set of files.

fn Files::add( self : Files, path : String, body : Bytes, media_type? : String) -> Unit

fnAdd body under path (/logo.svg, say). The media type is guessed from the extension unless one is given.

fn Files::get(self : Files, path : String) -> FileEntry?

fnThe file registered under path, or None.

fn Files::paths(self : Files) -> Array[String]

fnThe paths in this set, sorted, so a listing or a test is stable.

fn media_type_of(path : String) -> String

fnThe media type for a path, from its extension. The table covers the types a static bundle actually carries; anything else is served as application/octet-stream, which every client downloads rather than guesses.

fn FileEntry::etag(self : FileEntry) -> String

fnThe ETag of a file: a quoted, strong validator derived from the length and a CRC-32 of the bytes, so two builds that produce the same content serve the same tag.

fn file_server(files : Files, prefix : String) -> Middleware

fnThe file-serving layer: a GET under prefix whose remaining path names a registered file is answered with it, and every other request reaches the application. A conditional request whose If-None-Match names the file's tag is answered 304 without the body. This is a middleware rather than a route so it composes with the assembled chain exactly as the reference implementation's does: the file response still carries the CORS, trace and access-log layers.