aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlban Gruin2020-09-13 16:41:04 +0200
committerAlban Gruin2020-09-13 16:42:20 +0200
commit2241454988c31521c1f4ff6029399a999396897b (patch)
tree3b137047078c7ef0ce5eb0a5c9c86d9e4f0a6800
parent9da797daf063aa3234dbdfb6a1105f391c4c2bae (diff)
ucs: add URLs to the HTML pages, read parameters in the URL
Signed-off-by: Alban Gruin <alban at pa1ch dot fr>
-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