add charset to various mime types
This commit is contained in:
parent
041f1d2640
commit
281e285673
1 changed files with 19 additions and 9 deletions
|
@ -46,16 +46,26 @@ let safe_seg path =
|
||||||
else Fmt.kstr (fun s -> Error (`Msg s)) "unsafe path %S" path
|
else Fmt.kstr (fun s -> Error (`Msg s)) "unsafe path %S" path
|
||||||
|
|
||||||
(* mime lookup with orb knowledge *)
|
(* mime lookup with orb knowledge *)
|
||||||
|
let append_charset = function
|
||||||
|
(* mime types from nginx:
|
||||||
|
http://nginx.org/en/docs/http/ngx_http_charset_module.html#charset_types *)
|
||||||
|
| "text/html" | "text/xml" | "text/plain" | "text/vnd.wap.wml"
|
||||||
|
| "application/javascript" | "application/rss+xml" | "application/atom+xml"
|
||||||
|
as content_type ->
|
||||||
|
content_type ^ "; charset=utf-8" (* default to utf-8 *)
|
||||||
|
| content_type -> content_type
|
||||||
|
|
||||||
let mime_lookup path =
|
let mime_lookup path =
|
||||||
match Fpath.to_string path with
|
append_charset
|
||||||
| "build-environment" | "opam-switch" | "system-packages" ->
|
(match Fpath.to_string path with
|
||||||
"text/plain"
|
| "build-environment" | "opam-switch" | "system-packages" ->
|
||||||
| _ ->
|
"text/plain"
|
||||||
if Fpath.has_ext "build-hashes" path
|
| _ ->
|
||||||
then "text/plain"
|
if Fpath.has_ext "build-hashes" path
|
||||||
else if Fpath.is_prefix Fpath.(v "bin/") path
|
then "text/plain"
|
||||||
then "application/octet-stream"
|
else if Fpath.is_prefix Fpath.(v "bin/") path
|
||||||
else Magic_mime.lookup (Fpath.to_string path)
|
then "application/octet-stream"
|
||||||
|
else Magic_mime.lookup (Fpath.to_string path))
|
||||||
|
|
||||||
let string_of_html =
|
let string_of_html =
|
||||||
Format.asprintf "%a" (Tyxml.Html.pp ())
|
Format.asprintf "%a" (Tyxml.Html.pp ())
|
||||||
|
|
Loading…
Reference in a new issue