Skip to main content

Module files

Module files 

Source
Expand description

Serving a static surface: a generated directory answered under its mount.

The directory is the producer’s output and this module never writes to it. What it adds is the three things a directory of files is not: a request path resolved safely into it, a media type, and a validator for the bytes it hands back.

Safety is by construction rather than by inspection. A request path is decomposed into segments, every segment is checked against a conservative character set, and any segment that is empty, . or .. refuses the request before the filesystem is touched; the resolved path is then canonicalised and required to still be inside the canonical root, which closes the door a symlink inside the directory would otherwise open. There is no path concatenation of untrusted text anywhere in this file.

Structs§

Files
A static surface, ready to answer.

Constants§

CACHE_MAX_BYTES
The largest file answered from memory. Anything larger is read per request rather than held: a documentation tree is small, and a cache with no ceiling is a leak with a plan.
DOCUMENT_CACHE
How long a browser may keep a document. Conservative: the pages are rebuilt from a working tree a person is editing, and a cached page that is one build behind is worse than a request.
IMMUTABLE_CACHE
How long a browser may keep an asset whose name carries a content hash. Zola writes such names for nothing today, so this is used only where the name proves it is safe.

Functions§

media_type
The media type of a file name, when it is one a static surface serves.
safe_relative
A request path made safe to join onto a surface’s root, or none.