diff options
author | Alban Gruin | 2020-12-30 17:40:57 +0100 |
---|---|---|
committer | Alban Gruin | 2020-12-30 17:40:57 +0100 |
commit | 3e9d3b3437f2d63a47f9c962ba9187c5ef692328 (patch) | |
tree | 8b1f5e122ac9caeff3f56849a516e7b10d788d80 /src/server.ml | |
parent | 8dff924f4d598da653794e29fb9929017e161aa3 (diff) |
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 <alban at pa1ch dot fr>
Diffstat (limited to 'src/server.ml')
-rw-r--r-- | src/server.ml | 15 |
1 files changed, 14 insertions, 1 deletions
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" () |