@@ -688,11 +688,14 @@ module Route = struct
688688
689689 type (_, _) t =
690690 | Fire : ('b , 'b ) t
691- | Rest : (string -> 'b , 'b ) t
691+ | Rest : {
692+ url_encoded : bool ;
693+ } -> (string -> 'b , 'b ) t
692694 | Compose : ('a , 'b ) comp * ('b , 'c ) t -> ('a , 'c ) t
693695
694696 let return = Fire
695- let rest = Rest
697+ let rest_of_path = Rest {url_encoded= false }
698+ let rest_of_path_urlencoded = Rest {url_encoded= true }
696699 let (@/) a b = Compose (a,b)
697700 let string = String
698701 let string_urlencoded = String_urlencoded
@@ -705,9 +708,19 @@ module Route = struct
705708 begin match path, route with
706709 | [] , Fire -> Some f
707710 | _ , Fire -> None
708- | _ , Rest ->
711+ | _ , Rest {url_encoded} ->
709712 let whole_path = String. concat " /" path in
710- Some (f whole_path)
713+ begin match
714+ if url_encoded
715+ then match Tiny_httpd_util. percent_decode whole_path with
716+ | Some s -> s
717+ | None -> raise_notrace Exit
718+ else whole_path
719+ with
720+ | whole_path ->
721+ Some (f whole_path)
722+ | exception Exit -> None
723+ end
711724 | (c1 :: path' ), Compose (comp , route' ) ->
712725 begin match comp with
713726 | Int ->
@@ -735,7 +748,8 @@ module Route = struct
735748 : type a b . Buffer. t -> (a ,b ) t -> unit
736749 = fun out -> function
737750 | Fire -> bpf out " /"
738- | Rest -> bpf out " <rest>"
751+ | Rest {url_encoded} ->
752+ bpf out " <rest_of_url%s>" (if url_encoded then " _urlencoded" else " " )
739753 | Compose (Exact s , tl ) -> bpf out " %s/%a" s pp_ tl
740754 | Compose (Int, tl ) -> bpf out " <int>/%a" pp_ tl
741755 | Compose (String, tl ) -> bpf out " <str>/%a" pp_ tl
0 commit comments