Skip to content

Commit

Permalink
Fix 2955
Browse files Browse the repository at this point in the history
  • Loading branch information
Cuihtlauac ALVARADO committed Feb 13, 2025
1 parent 400b65c commit 069ed03
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/ocamlorg_web/lib/router.ml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,18 @@ let graphql_route t =
Dream.get "/graphiql" (Dream.graphiql "/graphql");
]

let ( let+ ) x f = Lwt.map f x

let middleware_text_utf8 handler request =
let+ response = handler request in
let ( let& ) opt some = Option.fold ~none:response ~some opt in
let headers = Dream.all_headers response in
let& content_type = List.assoc_opt "Content-Type" headers in
let& _ = if String.starts_with ~prefix:"text/plain" content_type then Some () else None in
Dream.drop_header response "Content-Type";
Dream.add_header response "Content-Type" (content_type ^ "; charset=utf-8");
response

let router t =
Dream.router
[
Expand All @@ -137,7 +149,7 @@ let router t =
graphql_route t;
sitemap_routes;
Dream.scope ""
[ Dream_encoding.compress ]
[ Dream_encoding.compress; middleware_text_utf8 ]
[ Dream.get "/manual/**" (Dream.static Config.manual_path) ];
Dream.scope ""
[ Dream_encoding.compress ]
Expand Down

0 comments on commit 069ed03

Please sign in to comment.