From 3e9d3b3437f2d63a47f9c962ba9187c5ef692328 Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Wed, 30 Dec 2020 17:40:57 +0100 Subject: ics: print the timezone name in the ICS file Add the correct timezone in generated ICS files. The timezone is fetched from /etc/timezone. Even though this is not standard, if a tool needs it, it should be able to understand it correctly. Signed-off-by: Alban Gruin --- src/server.ml | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src/server.ml') diff --git a/src/server.ml b/src/server.ml index d3cf00e..c1a0ba9 100644 --- a/src/server.ml +++ b/src/server.ml @@ -47,7 +47,20 @@ 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 get_tz () = + Lwt_unix.file_exists "/etc/timezone" >>= fun exists -> + if exists then + Lwt_io.(open_file ~mode:Input "/etc/timezone") >>= fun file -> + Lwt.finalize + (fun () -> + Lwt_io.read file >|= + String.trim) + (fun () -> Lwt_io.close file) + else + Lwt.return "" + let serve base_url celcat_url mode stop = + get_tz () >>= fun tzname -> let fetch = fetch celcat_url in let callback _conn req _body = let meth = Request.meth req and @@ -68,7 +81,7 @@ let serve base_url celcat_url mode stop = let group = String.(sub file 0 (length file - 4)) in fetch group >>= fun body -> Course.decode body - |> Ics.to_string + |> Ics.to_string tzname |> respond ~mime:"text/calendar; charset=utf-8" | `GET, _, _ -> Server.respond_string ~status:`Not_found ~body:"Not found\n" () -- cgit v1.2.1