diff --git a/dev/tiny_httpd/Tiny_httpd_dir/Embedded_fs/index.html b/dev/tiny_httpd/Tiny_httpd_dir/Embedded_fs/index.html deleted file mode 100644 index 3335db38..00000000 --- a/dev/tiny_httpd/Tiny_httpd_dir/Embedded_fs/index.html +++ /dev/null @@ -1,2 +0,0 @@ - -
Tiny_httpd_dir.Embedded_fsAn embedded file system, as a list of files with (relative) paths. This is useful in combination with the "tiny-httpd-mkfs" tool, which embeds the files it's given into a OCaml module.
val create : ?mtime:float -> unit -> tval add_file : ?mtime:float -> t -> path:string -> string -> unitAdd file to the virtual file system.
Tiny_httpd_dir.VFSVirtual file system.
This is used to emulate a file system from pure OCaml functions and data, e.g. for resources bundled inside the web server.
file_exists vfs path returns true if path points to a file or directory inside vfs.
List directory. This only returns basenames, the files need to be put in the directory path using Filename.concat.
Create a file and obtain a pair write, close
val read_file_content : string -> Tiny_httpd_stream.tRead content of a file
Tiny_httpd_html_.AAttributes.
This module contains combinator for the standard attributes. One can also just use a pair of strings.
type t = string -> attributeAttribute builder
val accept : tAttribute "accept".
val accept_charset : tAttribute "accept-charset".
val accesskey : tAttribute "accesskey".
val action : tAttribute "action".
val align : tAttribute "align".
val allow : tAttribute "allow".
val alt : tAttribute "alt".
val async : tAttribute "async".
val autocapitalize : tAttribute "autocapitalize".
val autocomplete : tAttribute "autocomplete".
val autofocus : tAttribute "autofocus".
val autoplay : tAttribute "autoplay".
val buffered : tAttribute "buffered".
val capture : tAttribute "capture".
val challenge : tAttribute "challenge".
val charset : tAttribute "charset".
val checked : tAttribute "checked".
val cite : tAttribute "cite".
val class_ : tAttribute "class".
val code : tAttribute "code".
val codebase : tAttribute "codebase".
val cols : tAttribute "cols".
val colspan : tAttribute "colspan".
val content : tAttribute "content".
val contenteditable : tAttribute "contenteditable".
Attribute "contextmenu".
val controls : tAttribute "controls".
val coords : tAttribute "coords".
val crossorigin : tAttribute "crossorigin".
val csp : tAttribute "csp".
val data : tAttribute "data".
val data_star : tAttribute "data-*".
val datetime : tAttribute "datetime".
val decoding : tAttribute "decoding".
val default : tAttribute "default".
val defer : tAttribute "defer".
val dir : tAttribute "dir".
val dirname : tAttribute "dirname".
val disabled : tAttribute "disabled".
val download : tAttribute "download".
val draggable : tAttribute "draggable".
val enctype : tAttribute "enctype".
val enterkeyhint : tAttribute "enterkeyhint".
val for_ : tAttribute "for".
val form : tAttribute "form".
val formaction : tAttribute "formaction".
val formenctype : tAttribute "formenctype".
val formmethod : tAttribute "formmethod".
val formnovalidate : tAttribute "formnovalidate".
val formtarget : tAttribute "formtarget".
val headers : tAttribute "headers".
Attribute "hidden".
val high : tAttribute "high".
val href : tAttribute "href".
val hreflang : tAttribute "hreflang".
val http_equiv : tAttribute "http-equiv".
val icon : tAttribute "icon".
val id : tAttribute "id".
val importance : tAttribute "importance".
val integrity : tAttribute "integrity".
val ismap : tAttribute "ismap".
val itemprop : tAttribute "itemprop".
val keytype : tAttribute "keytype".
val kind : tAttribute "kind".
val label : tAttribute "label".
val lang : tAttribute "lang".
val language : tAttribute "language".
val list : tAttribute "list".
val loop : tAttribute "loop".
val low : tAttribute "low".
val manifest : tAttribute "manifest".
val max : tAttribute "max".
val maxlength : tAttribute "maxlength".
val minlength : tAttribute "minlength".
val media : tAttribute "media".
val method_ : tAttribute "method".
val min : tAttribute "min".
val multiple : tAttribute "multiple".
val muted : tAttribute "muted".
val name : tAttribute "name".
val novalidate : tAttribute "novalidate".
val open_ : tAttribute "open".
val optimum : tAttribute "optimum".
val pattern : tAttribute "pattern".
val ping : tAttribute "ping".
val placeholder : tAttribute "placeholder".
val poster : tAttribute "poster".
val preload : tAttribute "preload".
val radiogroup : tAttribute "radiogroup".
val readonly : tAttribute "readonly".
val referrerpolicy : tAttribute "referrerpolicy".
val rel : tAttribute "rel".
val required : tAttribute "required".
val reversed : tAttribute "reversed".
val rows : tAttribute "rows".
val rowspan : tAttribute "rowspan".
val sandbox : tAttribute "sandbox".
val scope : tAttribute "scope".
val scoped : tAttribute "scoped".
val selected : tAttribute "selected".
val shape : tAttribute "shape".
val size : tAttribute "size".
val sizes : tAttribute "sizes".
val slot : tAttribute "slot".
val span : tAttribute "span".
val spellcheck : tAttribute "spellcheck".
val src : tAttribute "src".
val srcdoc : tAttribute "srcdoc".
val srclang : tAttribute "srclang".
val srcset : tAttribute "srcset".
val start : tAttribute "start".
val step : tAttribute "step".
val style : tAttribute "style".
val summary : tAttribute "summary".
val tabindex : tAttribute "tabindex".
val target : tAttribute "target".
val title : tAttribute "title".
val translate : tAttribute "translate".
val text : tAttribute "Text".
val type_ : tAttribute "type".
val usemap : tAttribute "usemap".
val value : tAttribute "value".
val width : tAttribute "width".
val wrap : tAttribute "wrap".
Tiny_httpd_html_.OutOutput for HTML combinators.
This output type is used to produce a string reasonably efficiently from a tree of combinators.
val create : unit -> tval clear : t -> unitval add_char : t -> char -> unitval add_string : t -> string -> unitval add_format_nl : t -> unitval with_no_format_nl : t -> (unit -> 'a) -> 'aval to_string : t -> stringTiny_httpd_server.HeadersThe header files of a request or response.
Neither the key nor the value can contain '\r' or '\n'. See https://tools.ietf.org/html/rfc7230#section-3.2
val empty : tEmpty list of headers
val get : ?f:(string -> string) -> string -> t -> string optionget k headers looks for the header field with key k.
set k v headers sets the key k to value v. It erases any previous entry for k
val contains : string -> t -> boolIs there a header with the given key?
val pp : Stdlib.Format.formatter -> t -> unitPretty print the headers.
Tiny_httpd_server.MethA HTTP method. For now we only handle a subset of these.
See https://tools.ietf.org/html/rfc7231#section-4
val pp : Stdlib.Format.formatter -> t -> unitval to_string : t -> stringTiny_httpd_server.MiddlewareA middleware can be inserted in a handler to modify or observe its behavior.
type handler = byte_stream Request.t -> resp:(Response.t -> unit) -> unitHandlers are functions returning a response to a request. The response can be delayed, hence the use of a continuation as the resp parameter.
A middleware is a handler transformation.
It takes the existing handler h, and returns a new one which, given a query, modify it or log it before passing it to h, or fail. It can also log or modify or drop the response.
val nil : tTrivial middleware that does nothing.
Tiny_httpd_server.Requesttype 'body t = private {meth : Meth.t;host : string;headers : Headers.t;http_version : int * int;path : string;path_components : string list;query : (string * string) list;body : 'body;start_time : float;}A request with method, path, host, headers, and a body, sent by a client.
The body is polymorphic because the request goes through several transformations. First it has no body, as only the request and headers are read; then it has a stream body; then the body might be entirely read as a string via read_body_full.
val pp : Stdlib.Format.formatter -> string t -> unitPretty print the request and its body
val pp_ : Stdlib.Format.formatter -> _ t -> unitPretty print the request without its body
val get_header : ?f:(string -> string) -> _ t -> string -> string optionval get_header_int : _ t -> string -> int optionset_header k v req sets k: v in the request req's headers.
val host : _ t -> stringHost field of the request. It also appears in the headers.
val path : _ t -> stringRequest path.
val body : 'b t -> 'bRequest body, possibly empty.
val start_time : _ t -> floattime stamp (from Unix.gettimeofday) after parsing the first line of the request
val limit_body_size : max_size:int -> byte_stream t -> byte_stream tLimit the body size to max_size bytes, or return a 413 error.
val read_body_full : ?buf_size:int -> byte_stream t -> string tRead the whole body into a string. Potentially blocking.
Tiny_httpd_server.ResponseBody of a response, either as a simple string, or a stream of bytes, or nothing (for server-sent events).
type t = private {code : Response_code.t;headers : Headers.t;Headers of the reply. Some will be set by Tiny_httpd automatically.
body : body;Body of the response. Can be empty.
*)}A response to send back to a client.
val set_code : Response_code.t -> t -> tSet the response code.
val make_raw : ?headers:Headers.t -> code:Response_code.t -> string -> tMake a response from its raw components, with a string body. Use "" to not send a body at all.
val make_raw_stream :
- ?headers:Headers.t ->
- code:Response_code.t ->
- byte_stream ->
- tSame as make_raw but with a stream body. The body will be sent with the chunked transfer-encoding.
val make :
- ?headers:Headers.t ->
- (body, Response_code.t * string) Stdlib.result ->
- tmake r turns a result into a response.
make (Ok body) replies with 200 and the body.make (Error (code,msg)) replies with the given error code and message as body.val make_string :
- ?headers:Headers.t ->
- (string, Response_code.t * string) Stdlib.result ->
- tSame as make but with a string body.
val make_stream :
- ?headers:Headers.t ->
- (byte_stream, Response_code.t * string) Stdlib.result ->
- tSame as make but with a stream body.
Make the current request fail with the given code and message. Example: fail ~code:404 "oh noes, %s not found" "waldo".
Similar to fail but raises an exception that exits the current handler. This should not be used outside of a (path) handler. Example: fail_raise ~code:404 "oh noes, %s not found" "waldo"; never_executed()
val pp : Stdlib.Format.formatter -> t -> unitPretty print the response.
Tiny_httpd_server.Response_codeval ok : tThe code 200
val not_found : tThe code 404
val descr : t -> stringA description of some of the error codes. NOTE: this is not complete (yet).
Tiny_httpd_server.RouteBasic type-safe routing.
val int : (int -> 'a, 'a) compMatches an integer.
val string : (string -> 'a, 'a) compMatches a string not containing '/' and binds it as is.
val string_urlencoded : (string -> 'a, 'a) compMatches a URL-encoded string, and decodes it.
val exact : string -> ('a, 'a) compexact "s" matches "s" and nothing else.
val return : ('a, 'a) tMatches the empty path.
val rest_of_path : (string -> 'a, 'a) tMatches a string, even containing '/'. This will match the entirety of the remaining route.
val rest_of_path_urlencoded : (string -> 'a, 'a) tMatches a string, even containing '/', an URL-decode it. This will match the entirety of the remaining route.
comp / route matches "foo/bar/…" iff comp matches "foo", and route matches "bar/…".
exact_path "foo/bar/..." r is equivalent to exact "foo" @/ exact "bar" @/ ... @/ r
val pp : Stdlib.Format.formatter -> (_, _) t -> unitPrint the route.
val to_string : (_, _) t -> stringPrint the route.
Tiny_httpd_server.SERVER_SENT_GENERATORA server-side function to generate of Server-sent events.
See the w3c page and this blog post.
val set_headers : Headers.t -> unitSet headers of the response. This is not mandatory but if used at all, it must be called before any call to send_event (once events are sent the response is already sent too).