Skip to content

Commit

Permalink
Redirectmod: removing deprecated (and ambiguous) regexp option
Browse files Browse the repository at this point in the history
  • Loading branch information
balat committed Aug 21, 2024
1 parent 932ab7a commit 7904589
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 27 deletions.
34 changes: 8 additions & 26 deletions src/extensions/redirectmod.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,15 @@ let section = Lwt_log.Section.make "ocsigen:ext:redirectmod"

(* The table of redirections for each virtual server *)
type redirection =
{ r_regexp : Pcre.regexp
; r_dest : string
; r_full : [`Yes | `No | `Maybe]
; r_temp : bool }
{r_regexp : Pcre.regexp; r_dest : string; r_full : bool; r_temp : bool}

let create_redirection ?(full_url = `Yes) ?(temporary = false) ~regexp r_dest =
let create_redirection ?(full_url = true) ?(temporary = false) ~regexp r_dest =
let r_regexp = Pcre.regexp ("^" ^ regexp ^ "$") in
{ r_regexp
; r_dest
; r_full = (full_url :> [`Yes | `No | `Maybe])
; r_temp = temporary }
{r_regexp; r_dest; r_full = full_url; r_temp = temporary}

let attempt_redir {r_regexp; r_dest; r_full; r_temp} _err ri () =
Lwt_log.ign_info ~section "Is it a redirection?";
let redir =
let find full =
Ocsigen_extensions.find_redirection r_regexp full r_dest ri
in
match r_full with
| `Yes -> find true
| `No -> find false
| `Maybe -> (
try find false with Ocsigen_extensions.Not_concerned -> find true)
in
let redir = Ocsigen_extensions.find_redirection r_regexp r_full r_dest ri in
Lwt_log.ign_info_f ~section "YES! %s redirection to: %s"
(if r_temp then "Temporary " else "Permanent ")
redir;
Expand All @@ -76,23 +61,20 @@ let gen dir = function
let parse_config config_elem =
let regexp = ref None
and dest = ref ""
and mode = ref `Yes
and mode = ref true
and temporary = ref false in
Ocsigen_extensions.(
Configuration.process_element ~in_tag:"host"
~other_elements:(fun t _ _ -> raise (Bad_config_tag_for_extension t))
~elements:
[ Configuration.element ~name:"redirect"
~attributes:
[ Configuration.attribute ~name:"regexp" (fun s ->
regexp := Some ("^" ^ s ^ "$");
mode := `Maybe)
; Configuration.attribute ~name:"fullurl" (fun s ->
[ Configuration.attribute ~name:"fullurl" (fun s ->
regexp := Some s;
mode := `Yes)
mode := true)
; Configuration.attribute ~name:"suburl" (fun s ->
regexp := Some s;
mode := `No)
mode := false)
; Configuration.attribute ~name:"dest" ~obligatory:true (fun s ->
dest := s)
; Configuration.attribute ~name:"temporary" (function
Expand Down
2 changes: 1 addition & 1 deletion src/extensions/redirectmod.mli
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ val section : Lwt_log_core.section
type redirection

val create_redirection :
?full_url:[< `Maybe | `No | `Yes > `Yes]
?full_url:bool
-> ?temporary:bool
-> regexp:string
-> string
Expand Down

0 comments on commit 7904589

Please sign in to comment.