aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ucs.ml10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/ucs.ml b/src/ucs.ml
index c9fcf95..eb99d95 100644
--- a/src/ucs.ml
+++ b/src/ucs.ml
@@ -36,6 +36,10 @@ let log req =
Printer.Calendar.sprint "%Y-%m-%d %H:%M:%S" @@ Calendar.now ()) in
Lwt_io.printlf "[%s] %s" datetime (Uri.path uri)
+let respond ?(mime="text/html; charset=utf-8") ?(status=`OK) body =
+ let headers = Header.init_with "Content-Type" mime in
+ Server.respond_string ~status ~body ~headers ()
+
let server =
let callback _conn req _body =
let meth = Request.meth req and
@@ -48,9 +52,9 @@ let server =
| `GET, ["ics"; file] when Astring.String.is_suffix ~affix:".ics" file ->
let group = String.(sub file 0 (length file - 4)) in
fetch group >>= fun body ->
- let body = Ics.to_string @@ Course.decode body and
- headers = Header.init_with "Content-Type" "text/calendar" in
- Server.respond_string ~status:`OK ~body ~headers ()
+ Course.decode body
+ |> Ics.to_string
+ |> respond ~mime:"text/calendar; charset=utf-8"
| `GET, _ ->
Server.respond_string ~status:`Not_found ~body:"Not found\n" ()
| _ ->