+ wip tos
This commit is contained in:
parent
98ba917cfb
commit
7ccd0ac600
2 changed files with 25 additions and 15 deletions
|
|
@ -16,10 +16,10 @@ type t =
|
||||||
| Terms
|
| Terms
|
||||||
| Privacy
|
| Privacy
|
||||||
|
|
||||||
|
(* TODO etag = filename *)
|
||||||
let etag k =
|
let etag k =
|
||||||
Result.get_ok
|
let etag = match k with Terms -> "0" | Privacy -> "0" in
|
||||||
@@ Headers_lib.Etag.of_crockford32
|
etag |> Headers_lib.Etag.of_crockford32 |> Result.get_ok
|
||||||
@@ match k with Terms -> "0" | Privacy -> "0"
|
|
||||||
|
|
||||||
let legal_version = function
|
let legal_version = function
|
||||||
| Terms -> terms_legal_version
|
| Terms -> terms_legal_version
|
||||||
|
|
@ -107,30 +107,40 @@ module Mimetype = struct
|
||||||
(("image", "gif"), ".gif");
|
(("image", "gif"), ".gif");
|
||||||
]
|
]
|
||||||
|
|
||||||
let all_supported, _ = List.split assoc
|
let all_supported =
|
||||||
|
let all_supported, all_supported_ext = List.split assoc in
|
||||||
|
match
|
||||||
|
Array.find_opt
|
||||||
|
(fun ext -> not @@ List.exists (( = ) ext) all_supported_ext)
|
||||||
|
supported_ext_arr
|
||||||
|
with
|
||||||
|
| Some ext -> Fmt.failwith "extension `%s` unsupported" ext
|
||||||
|
| None -> all_supported
|
||||||
|
|
||||||
let of_cohttp_media = function
|
let default = default_mimetype
|
||||||
|
|
||||||
|
let of_cohttp = function
|
||||||
| Cohttp.Accept.MediaType (m, m_sub) ->
|
| Cohttp.Accept.MediaType (m, m_sub) ->
|
||||||
List.find_opt (( = ) (m, m_sub)) all_supported
|
List.find_opt (( = ) (m, m_sub)) all_supported
|
||||||
| AnyMediaSubtype m ->
|
| AnyMediaSubtype m ->
|
||||||
List.find_opt (fun (m', _) -> String.equal m m') all_supported
|
List.find_opt (fun (m', _) -> String.equal m m') all_supported
|
||||||
| AnyMedia -> Some default_mimetype
|
| AnyMedia -> Some default
|
||||||
|
|
||||||
let to_extension t =
|
let to_extension_exn t =
|
||||||
match List.assoc_opt t assoc with
|
match List.assoc_opt t assoc with
|
||||||
| None ->
|
| None ->
|
||||||
Fmt.failwith "Mimetype.to_extension failure: `%s/%s` unknown" (fst t)
|
Fmt.failwith "Mimetype.to_extension failure: `%s/%s` unknown" (fst t)
|
||||||
(snd t)
|
(snd t)
|
||||||
| Some ext -> ext
|
| Some ext -> ext
|
||||||
|
|
||||||
let is_supported mime = List.mem mime all_supported
|
|
||||||
end
|
end
|
||||||
|
|
||||||
module Language = struct
|
module Language = struct
|
||||||
type t = string
|
type t = string
|
||||||
|
|
||||||
let of_cohttp_language = function
|
let default = default_lang
|
||||||
| Cohttp.Accept.AnyLanguage -> Some default_lang
|
|
||||||
|
let of_cohttp = function
|
||||||
|
| Cohttp.Accept.AnyLanguage -> Some default
|
||||||
| Language language_range -> (
|
| Language language_range -> (
|
||||||
(* ignore language subtags (e.g. "en-US" -> "en") *)
|
(* ignore language subtags (e.g. "en-US" -> "en") *)
|
||||||
match language_range with
|
match language_range with
|
||||||
|
|
@ -142,7 +152,7 @@ end
|
||||||
(* ! lang and mime must be supported *)
|
(* ! lang and mime must be supported *)
|
||||||
let get_content ~lang ~mime t =
|
let get_content ~lang ~mime t =
|
||||||
let etag = Headers_lib.Etag.to_raw_string (etag t) in
|
let etag = Headers_lib.Etag.to_raw_string (etag t) in
|
||||||
let ext = Mimetype.to_extension mime in
|
let ext = Mimetype.to_extension_exn mime in
|
||||||
let path = Fpath.to_string Fpath.((v (base_dir t) / lang / etag) + ext) in
|
let path = Fpath.to_string Fpath.((v (base_dir t) / lang / etag) + ext) in
|
||||||
match Assets_crunch.read path with
|
match Assets_crunch.read path with
|
||||||
| None -> Fmt.failwith "static file not found: `%s`" path
|
| None -> Fmt.failwith "static file not found: `%s`" path
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ let select_mimetype headers =
|
||||||
let opt = Vif.Headers.get headers "accept" in
|
let opt = Vif.Headers.get headers "accept" in
|
||||||
Cohttp.Accept.media_ranges opt
|
Cohttp.Accept.media_ranges opt
|
||||||
|> Cohttp.Accept.qsort
|
|> Cohttp.Accept.qsort
|
||||||
|> List.find_map (fun (_q, (m, _p)) -> Assets.Mimetype.of_cohttp_media m)
|
|> List.find_map (fun (_q, (m, _p)) -> Assets.Mimetype.of_cohttp m)
|
||||||
|> function
|
|> function
|
||||||
| None -> Assets.default_mimetype
|
| None -> Assets.default_mimetype
|
||||||
| Some mime -> mime
|
| Some mime -> mime
|
||||||
|
|
@ -24,9 +24,9 @@ let select_language headers =
|
||||||
Cohttp.Accept.languages opt
|
Cohttp.Accept.languages opt
|
||||||
|> Cohttp.Accept.qsort
|
|> Cohttp.Accept.qsort
|
||||||
|> List.map snd
|
|> List.map snd
|
||||||
|> List.find_map Assets.Language.of_cohttp_language
|
|> List.find_map Assets.Language.of_cohttp
|
||||||
|> function
|
|> function
|
||||||
| None -> Assets.default_lang
|
| None -> Assets.Language.default
|
||||||
| Some lang -> lang
|
| Some lang -> lang
|
||||||
|
|
||||||
let select_encoding headers =
|
let select_encoding headers =
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue