Skip to main content

Module static_files

Module static_files 

Source
Expand description

The static file module which powers the web server.

The request pipeline is intentionally linear and reads top-to-bottom in handle:

  1. Method checkGET, HEAD and OPTIONS only.
  2. Path sanitization — strip traversal components from the URI path.
  3. In-memory cache lookup — short-circuit hot files.
  4. File resolution — directory → index, .html fallback, pre-compressed variant detection (see [resolve]).
  5. Security checks — containment, symlink and hidden-file policy (see [security]).
  6. Short-circuit responses — trailing-slash redirect, OPTIONS, directory listing or archive download.
  7. File reply — stream the resolved file or its pre-compressed variant (see [reply]).

Structs§

HandleOpts
Defines all options needed by the static-files handler.
StaticFileResponse
Static file response type with additional data.

Functions§

handle
The server entry point to handle incoming requests which map to specific files on file system and return a file response.