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 (i.e. it drops the parameters). This parses and returns one or two tokens separated by /. Can be used on lowercased Http.Headers.content_type header values to match types.

Converting with file extensions

type fpath = string

The type for file paths.

type file_ext = string

The type for file extensions, including the . character.

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

The type for maps from file extensions to media types.

val of_file_ext : ?map:of_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:of_file_ext_map -> fpath -> t

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

val default_of_file_ext_map : of_file_ext_map

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

type to_file_ext_map = file_ext Stdlib.Map.Make(Stdlib.String).t

The type for maps from media types to file extensions.

val to_file_ext : ?map:to_file_ext_map -> t -> file_ext

to_file_ext ~map t is the value t in map or ".bin" if both t and to_type t are unbound in map. map defaults to default_to_file_ext_map.

val default_to_file_ext_map : of_file_ext_map

default_to_file_ex_map is a default media type to extension map. The map is documented by its implementation (sorry).