mirror of
https://github.com/c-cube/tiny_httpd.git
synced 2025-12-06 11:15:35 -05:00
feat: printing routes
This commit is contained in:
parent
a679ddf1d1
commit
aa66e172e8
2 changed files with 24 additions and 0 deletions
|
|
@ -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 "<int>/%a" pp_ tl
|
||||
| Compose (String, tl) -> bpf out "<str>/%a" pp_ tl
|
||||
| Compose (String_urlencoded, tl) -> bpf out "<enc_str>/%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 = {
|
||||
|
|
|
|||
|
|
@ -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} *)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue