Skip to content

Commit

Permalink
Fix 2955 (#2957)
Browse files Browse the repository at this point in the history
* Fix 2955

* Formatting

---------

Co-authored-by: Cuihtlauac ALVARADO <cuihtmlauac@tarides.com>
  • Loading branch information
cuihtlauac and Cuihtlauac ALVARADO authored Feb 14, 2025
1 parent fc277df commit 267c8a7
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/ocamlorg_web/lib/router.ml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,21 @@ 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 +152,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 267c8a7

Please sign in to comment.