diff --git a/src/Tiny_httpd.ml b/src/Tiny_httpd.ml index a409cea2..21f05d7e 100644 --- a/src/Tiny_httpd.ml +++ b/src/Tiny_httpd.ml @@ -724,6 +724,22 @@ module Route = struct | [], Compose (String_urlencoded, Fire) -> Some (f "") (* trailing *) | [], Compose _ -> None end + + let bpf = Printf.bprintf + let rec pp_ + : type a b. Buffer.t -> (a,b) t -> unit + = fun out -> function + | Fire -> 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 + | Compose (String_urlencoded, tl) -> bpf out "/%a" pp_ tl + + let to_string x = + let b = Buffer.create 16 in + pp_ b x; + Buffer.contents b + let pp out x = Format.pp_print_string out (to_string x) end type t = { diff --git a/src/Tiny_httpd.mli b/src/Tiny_httpd.mli index b890c2ed..497d35ff 100644 --- a/src/Tiny_httpd.mli +++ b/src/Tiny_httpd.mli @@ -400,6 +400,14 @@ module Route : sig val (@/) : ('a, 'b) comp -> ('b, 'c) t -> ('a, 'c) t (** [comp / route] matches ["foo/bar/…"] iff [comp] matches ["foo"], and [route] matches ["bar/…"]. *) + + val pp : Format.formatter -> _ t -> unit + (** Print the route. + @since NEXT_RELEASE *) + + val to_string : _ t -> string + (** Print the route. + @since NEXT_RELEASE *) end (** {2 Server} *)