Skip to content

Commit

Permalink
Static: don't set Content-Type on error responses
Browse files Browse the repository at this point in the history
Fixes #88.
  • Loading branch information
aantron committed Jul 2, 2021
1 parent cd8464e commit 809835d
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/middleware/static.ml
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,19 @@ let static ?(loader = from_filesystem) local_root = fun request ->

let%lwt response = loader local_root path request in

(* TODO Can use a concise helper here. *)
let response =
if Dream.has_header "Content-Type" response then
response
else
Dream.add_header "Content-Type" (Magic_mime.lookup path) response
match Dream.status response with
| `OK
| `Non_Authoritative_Information
| `No_Content
| `Reset_Content
| `Partial_Content ->
Dream.add_header "Content-Type" (Magic_mime.lookup path) response
| _ ->
response
in

Lwt.return response

0 comments on commit 809835d

Please sign in to comment.