aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ucs.ml21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/ucs.ml b/src/ucs.ml
index eb99d95..cda7bcc 100644
--- a/src/ucs.ml
+++ b/src/ucs.ml
@@ -43,19 +43,26 @@ let respond ?(mime="text/html; charset=utf-8") ?(status=`OK) body =
let server =
let callback _conn req _body =
let meth = Request.meth req and
- uri = Request.uri req
- |> Uri.path
- |> Astring.String.cuts ~empty:false ~sep:"/"
- |> List.map Uri.pct_decode in
+ uri = Request.uri req in
+ let path = Uri.path uri
+ |> Astring.String.cuts ~empty:false ~sep:"/"
+ |> List.map Uri.pct_decode and
+ query = Uri.query uri in
log req >>= fun () ->
- match meth, uri with
- | `GET, ["ics"; file] when Astring.String.is_suffix ~affix:".ics" file ->
+ match meth, path, query with
+ | `GET, ([] | ["index.html"]), [] -> respond Pages.main
+ | `GET, ["lnk"], ["group", [group]] ->
+ let lnk = "/ics/" ^ group ^ ".ics" in
+ respond @@ Pages.link lnk
+ | `GET, ["lnk"], _ ->
+ Server.respond_string ~status:`Bad_request ~body:"Bad request\n" ()
+ | `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 ->
Course.decode body
|> Ics.to_string
|> respond ~mime:"text/calendar; charset=utf-8"
- | `GET, _ ->
+ | `GET, _, _ ->
Server.respond_string ~status:`Not_found ~body:"Not found\n" ()
| _ ->
Server.respond_string