package simple_httpd
Install
dune-project
Dependency
Authors
Maintainers
Sources
md5=91bac42325d71caf3af41a26b0e6a2df
sha512=e34b117eb44899c2e299069143bf857122f35bb157d988137d6034892b8a6b419eec893c13a620b8d416a42246777d46291a715ed4e719be354e37651331dbf0
doc/simple_httpd/Simple_httpd/Dir/index.html
Module Simple_httpd.DirSource
Module to server directory structure (real of virtual)
Serving static content from directories
This module provides the same functionality as the "http_of_dir" tool. It exposes a directory (and its subdirectories), with the optional ability to delete or upload files.
type dir_behavior = | Index(*Redirect to index.html if present, else fails.
*)| Lists(*Lists content of directory. Be careful of security implications.
*)| Index_or_lists(*Redirect to index.html if present and lists content otherwise. This is useful for tilde ("~") directories and other per-user behavior, but be mindful of security implications
*)| Forbidden(*Forbid access to directory. This is suited for serving assets, for example.
*)
behavior of static directory.
This controls what happens when the user requests the path to a directory rather than a file.
type config = {mutable download : bool;(*Is downloading files allowed?
*)mutable dir_behavior : dir_behavior;(*Behavior when serving a directory and not a file
*)mutable delete : bool;(*Is deleting a file allowed? (with method DELETE)
*)mutable upload : bool;(*Is uploading a file allowed? (with method PUT)
*)mutable max_upload_size : int;
}configuration for static file handlers. This might get more fields over time.
default configuration: { download=true ; dir_behavior=Forbidden ; delete=false ; upload=false ; max_upload_size = 10 * 1024 * 1024 }
val config :
?download:bool ->
?dir_behavior:dir_behavior ->
?delete:bool ->
?upload:bool ->
?max_upload_size:int ->
unit ->
configBuild a config from default_config.
val add_dir_path :
?addresses:Address.t list ->
?filter:Input.t Filter.t ->
?prefix:string ->
?config:config ->
dir:string ->
Server.t ->
unitadd_dirpath ~config ~dir ~prefix server adds route handle to the server to serve static files in dir when url starts with prefix, using the given configuration config. Method is always GET.
Virtual file system.
This is used to emulate a file system from pure OCaml functions and data, e.g. for resources bundled (totally of partially) inside the web server memory.
VFS allows to serve dynamic content produced using such a record
dynamic content can set then headers, cookies and input of the response. If initial headers contain Headers.Cache_Control or Headers.Etag.
type 'a content = | String of string * string option(*
*)String(s,Some sz)is a fixed string content.sis the content,sz, if provided is a compressed version ofsproduced byCamlzip.| Path of string * (string * int) option(*
*)Path(fname,Some(fzname,size))is a real filefname, possibly with a compressed versionfznameof the givensize| Dynamic of dynamic(*Dynamic content
*)| Stream of Input.t(*Streamed content
*)| Fd of Unix.file_descr(*Content with a file descriptor, that will be send using sendfile.
*)| Dir of 'a(*Used internally
*)
Here is the type of content that can be served by a VFS
vfs_of_dir dir makes a virtual file system that reads from the disk.
val add_vfs :
?addresses:Address.t list ->
?filter:Input.t Filter.t ->
?prefix:string ->
?config:config ->
vfs:(module VFS) ->
Server.t ->
unitSimilar to add_dir_path but using a virtual file system instead.
An embedded file system, as a list of files with (relative) paths. This is useful in combination with the "simple-httpd-mkfs" tool, which embeds the files it's given into a OCaml module.