From 0309737ef7ae31d515dac98f6d7ccf786f54f868 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reynir=20Bj=C3=B6rnsson?= Date: Wed, 6 Jan 2021 14:28:10 +0100 Subject: [PATCH] Add orb mime knowledge --- lib/builder_web.ml | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/builder_web.ml b/lib/builder_web.ml index 4a15f32..9e2493e 100644 --- a/lib/builder_web.ml +++ b/lib/builder_web.ml @@ -14,6 +14,19 @@ let safe_seg path = then Ok (Fpath.v path) else Rresult.R.error_msgf "unsafe path %S" path +(* mime lookup with orb knowledge *) +let mime_lookup path = + match path with + | "build-environment" | "opam-switch" | "system-packages" -> + "text/plain" + | path -> + let path' = Fpath.v path in + if Fpath.has_ext "build-hashes" path' + then "text/plain" + else if Fpath.is_prefix Fpath.(v "bin/") path' + then "application/octet-stream" + else Magic_mime.lookup path + let routes (t : Model.t) = let builder _req = let+ jobs = Model.jobs t in @@ -91,7 +104,7 @@ let routes (t : Model.t) = let digest = snd (List.find (fun (p, _) -> Fpath.equal path p) digests) in let body = Body.of_string data in Response.make ~body () - |> Response.add_header ("Content-type", Magic_mime.lookup file) + |> Response.add_header ("Content-type", mime_lookup file) |> Response.set_etag (Base64.encode_string (Cstruct.to_string digest.sha256)) in