Hcs.Plug.Static
hcs · API reference
Static file serving plug.
Serves files from a directory with optional directory listing, index file lookup, and ETag support.
type config = {
index : string list; (* Index files to try for directories *)
listing : bool; (* Enable directory listing *)
dotfiles : bool; (* Serve dotfiles *)
}val default_config : configval string_starts_with : prefix:string -> string -> boolCheck if string starts with prefix
val extension : string -> stringGet file extension
val mime_type_of_extension : string -> stringMap file extension to MIME type
val html_escape : string -> stringHTML escape
val directory_listing : path:string -> (String.t * bool * int) list -> stringGenerate directory listing HTML
val normalize_path : string -> string optionNormalize and validate URL path to prevent directory traversal
val path_contains_symlink :
root:[> Eio.Fs.dir_ty ] Eio.Path.t ->
string ->
boolval generate_etag : String.t -> stringGenerate ETag from content
val server :
?config:config ->
[> Eio.Fs.dir_ty ] Eio.Path.t ->
Server.request ->
Server.responseCreate a static file server handler (not middleware).
Use this when static files are the only thing being served. root should be a directory capability already narrowed to the static root. Symlinks under root are rejected rather than followed.
val create :
?index:string list ->
?with_etag:bool ->
[> Eio.Fs.dir_ty ] Eio.Path.t ->
(Server.request -> Server.response) ->
Server.request ->
Server.responseCreate static file serving plug.
Serves files from root directory, falls back to next handler if not found.
parameter index Index files to try (default: "index.html") parameter with_etag Add ETag headers (default: true) parameter root Directory capability for the static root. Symlinks under this root are rejected rather than followed.