add content-type header
This commit is contained in:
parent
0447857d1e
commit
06332cac8c
4 changed files with 66 additions and 57 deletions
|
|
@ -24,8 +24,6 @@ let base_dir = function
|
|||
| Terms -> Config.terms_dir
|
||||
| Privacy -> Config.privacy_dir
|
||||
|
||||
let path ~lang ~ext t = Fpath.((base_dir t / lang / etag t) + ext)
|
||||
|
||||
(* TODO
|
||||
better use of Fmt to have error prefix or smthing
|
||||
use Logs *)
|
||||
|
|
@ -95,11 +93,21 @@ let supported_lang_arr, supported_ext_arr =
|
|||
in
|
||||
(Array.of_list lang_l, Array.of_list ext_l)
|
||||
|
||||
let supported_mimetype_arr =
|
||||
Array.map Util.extension_to_mimetype supported_ext_arr |> Array.map Option.get
|
||||
|
||||
let is_supported_lang lang = Array.mem lang supported_lang_arr
|
||||
let is_supported_ext ext = Array.mem ext supported_ext_arr
|
||||
let is_supported_mimetype mime = Array.mem mime supported_mimetype_arr
|
||||
|
||||
let get_content ~lang ~ext t =
|
||||
let path = Fpath.to_string (path ~lang ~ext t) in
|
||||
(* ! lang and mime must be supported *)
|
||||
let get_content ~lang ~mime t =
|
||||
let ext =
|
||||
match Util.mimetype_to_extension mime with
|
||||
| None -> Fmt.failwith "mimetype `%s/%s` unknown" (fst mime) (snd mime)
|
||||
| Some ext -> ext
|
||||
in
|
||||
let path = Fpath.to_string Fpath.((base_dir t / lang / etag t) + ext) in
|
||||
match Assets_crunch.read path with
|
||||
| None -> Fmt.error "static file not found: `%s`" path
|
||||
| Some data -> Ok data
|
||||
| None -> Fmt.failwith "static file not found: `%s`" path
|
||||
| Some data -> data
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue