From 4c3a5986d6e70c4cdd56744ccf9ad5d0e8f0fd0f Mon Sep 17 00:00:00 2001 From: Hannes Mehnert Date: Mon, 11 Apr 2022 16:23:45 +0200 Subject: [PATCH 1/4] Redirect /job to / and /job/:job/build to /job/:job replaces #81 --- lib/builder_web.ml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/builder_web.ml b/lib/builder_web.ml index 56523ab..e277c5d 100644 --- a/lib/builder_web.ml +++ b/lib/builder_web.ml @@ -476,11 +476,23 @@ let add_routes datadir configdir = >>= fun () -> Dream.respond "" |> Lwt_result.ok in + let redirect_parent req = + let path = Dream.target req in + let parent = + String.split_on_char '/' |> + List.rev |> List.tl |> List.rev |> + String.concat "/" + in + Dream.redirect ~status:`Temporary_Redirect req (parent ^ "/") + in + let w f req = or_error_response (f req) in Dream.router [ Dream.get "/" (w builds); + Dream.get "/job" (w redirect_parent); Dream.get "/job/:job/" (w job); + Dream.get "/job/:job/build" (w redirect_parent); Dream.get "/job/:job/failed/" (w job_with_failed); Dream.get "/job/:job/build/latest/**" (w redirect_latest); Dream.get "/job/:job/build/:build/" (w job_build); From 3bee8a357d25bba33099f77910d0ed6f1af292d5 Mon Sep 17 00:00:00 2001 From: Hannes Mehnert Date: Mon, 11 Apr 2022 16:54:28 +0200 Subject: [PATCH 2/4] add query params to redirect --- lib/builder_web.ml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/builder_web.ml b/lib/builder_web.ml index e277c5d..518eca6 100644 --- a/lib/builder_web.ml +++ b/lib/builder_web.ml @@ -477,13 +477,18 @@ let add_routes datadir configdir = in let redirect_parent req = - let path = Dream.target req in let parent = + Dream.target req |> String.split_on_char '/' |> List.rev |> List.tl |> List.rev |> String.concat "/" in - Dream.redirect ~status:`Temporary_Redirect req (parent ^ "/") + let parent = parent ^ "/" in + let url = match Dream.queries req with + | [] -> parent + | xs -> parent ^ (Dream.to_form_urlencoded xs) + in + Dream.redirect ~status:`Temporary_Redirect req url in let w f req = or_error_response (f req) in From a132a181c82390891bb68ca2079c9dc93d040781 Mon Sep 17 00:00:00 2001 From: Hannes Mehnert Date: Mon, 11 Apr 2022 17:08:10 +0200 Subject: [PATCH 3/4] add ? before query parameters --- lib/builder_web.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/builder_web.ml b/lib/builder_web.ml index 518eca6..258d12c 100644 --- a/lib/builder_web.ml +++ b/lib/builder_web.ml @@ -486,7 +486,7 @@ let add_routes datadir configdir = let parent = parent ^ "/" in let url = match Dream.queries req with | [] -> parent - | xs -> parent ^ (Dream.to_form_urlencoded xs) + | xs -> parent ^ "?" ^ (Dream.to_form_urlencoded xs) in Dream.redirect ~status:`Temporary_Redirect req url in From 010197d90066d6a8c21177a6785265deab011ab5 Mon Sep 17 00:00:00 2001 From: rand00 Date: Mon, 11 Apr 2022 18:19:54 +0200 Subject: [PATCH 4/4] Builder_web: Fixed type-errors + usage of correct dream queries helper --- lib/builder_web.ml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/builder_web.ml b/lib/builder_web.ml index cb07e61..1d918d6 100644 --- a/lib/builder_web.ml +++ b/lib/builder_web.ml @@ -476,11 +476,12 @@ let add_routes ~datadir ~cachedir ~configdir = String.concat "/" in let parent = parent ^ "/" in - let url = match Dream.queries req with + let url = match Dream.all_queries req with | [] -> parent | xs -> parent ^ "?" ^ (Dream.to_form_urlencoded xs) in Dream.redirect ~status:`Temporary_Redirect req url + |> Lwt_result.ok in let w f req = or_error_response (f req) in