Module Webs.Media_type

Media type constants and file extensions.

Media types

type t = string

The type for media types.

Constants

val none : t

none is "", a content type for when there is none.

val application_json : t

application_json is "application/json", JSON text.

val application_octet_stream : t

application_octet_stream is "application/octet-stream", arbitrary bytes.

val application_x_www_form_urlencoded : t

application_x_www_form_urlencoded is "application/x-www-form-urlencoded".

val text_css : t

text_css is "text/css", a CSS stylesheet.

val text_html : t

text_html is "text/html; charset=utf-8", UTF-8 encoded HTML text.

val text_javascript : t

text_jvascript is "text/javascript", JavaScript code.

val text_plain : t

text_plain is "text/plain; charset=utf-8", UTF-8 encoded plain text.

val multipart_byteranges : t

multipart_byteranges is "multipart/byteranges".

val multipart_form_data : t

multipart_form_data is "multipart/form-data".

Operations

val get_type : t -> string

get_type t is a lenient parser for the type/subtype part of the media-type t. This parses and returns one or two tokens separated by /. Can be used on lowercased Http.Headers.content_type header values to match types.

From file extensions

type fpath = string

The type for file paths.

type file_ext = string

The type for file extensions, including the . character.

type file_ext_map = t Stdlib.Map.Make(Stdlib.String).t

The type for maps from file extensions to media types.

val default_file_ext_map : file_ext_map

default_file_ext_map is a default extension map. The map is documented by its implementation (sorry). Non self-describing text/* media types have the parameter charset=utf-8.

val of_file_ext : ?map:file_ext_map -> file_ext -> t

of_file_ext ~map ext is the value of ext in map or "application/octet-stream" if ext is unbound in map. map defaults to default_file_ext_map.

val of_filepath : ?map:file_ext_map -> fpath -> t

of_filepath ~map f is of_file_ext ~map (Http.Path.filepath_ext f).