diff --git a/src/Tiny_httpd.ml b/src/Tiny_httpd.ml index 21f05d7e..c8d1d7e6 100644 --- a/src/Tiny_httpd.ml +++ b/src/Tiny_httpd.ml @@ -688,9 +688,11 @@ module Route = struct type (_, _) t = | Fire : ('b, 'b) t + | Rest : (string -> 'b, 'b) t | Compose: ('a, 'b) comp * ('b, 'c) t -> ('a, 'c) t let return = Fire + let rest = Rest let (@/) a b = Compose (a,b) let string = String let string_urlencoded = String_urlencoded @@ -703,6 +705,9 @@ module Route = struct begin match path, route with | [], Fire -> Some f | _, Fire -> None + | _, Rest -> + let whole_path = String.concat "/" path in + Some (f whole_path) | (c1 :: path'), Compose (comp, route') -> begin match comp with | Int -> @@ -730,6 +735,7 @@ module Route = struct : type a b. Buffer.t -> (a,b) t -> unit = fun out -> function | Fire -> bpf out "/" + | Rest -> bpf out "" | Compose (Exact s, tl) -> bpf out "%s/%a" s pp_ tl | Compose (Int, tl) -> bpf out "/%a" pp_ tl | Compose (String, tl) -> bpf out "/%a" pp_ tl diff --git a/src/Tiny_httpd.mli b/src/Tiny_httpd.mli index 497d35ff..c55674bf 100644 --- a/src/Tiny_httpd.mli +++ b/src/Tiny_httpd.mli @@ -386,7 +386,7 @@ module Route : sig (** Matches an integer. *) val string : (string -> 'a, 'a) comp - (** Matches a string and binds it as is. *) + (** Matches a string not containing ['/'] and binds it as is. *) val string_urlencoded : (string -> 'a, 'a) comp (** Matches a URL-encoded string, and decodes it. *) @@ -397,6 +397,11 @@ module Route : sig val return : ('a, 'a) t (** Matches the empty path. *) + val rest : (string -> 'a, 'a) t + (** Matches a string, even containing ['/']. This will match + the entirety of the remaining route. + @since NEXT_RELEASE *) + val (@/) : ('a, 'b) comp -> ('b, 'c) t -> ('a, 'c) t (** [comp / route] matches ["foo/bar/…"] iff [comp] matches ["foo"], and [route] matches ["bar/…"]. *)