mirror of
https://github.com/c-cube/tiny_httpd.git
synced 2025-12-06 19:25:32 -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 (String_urlencoded, Fire) -> Some (f "") (* trailing *)
|
||||||
| [], Compose _ -> None
|
| [], Compose _ -> None
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
type t = {
|
type t = {
|
||||||
|
|
|
||||||
|
|
@ -400,6 +400,14 @@ module Route : sig
|
||||||
val (@/) : ('a, 'b) comp -> ('b, 'c) t -> ('a, 'c) t
|
val (@/) : ('a, 'b) comp -> ('b, 'c) t -> ('a, 'c) t
|
||||||
(** [comp / route] matches ["foo/bar/…"] iff [comp] matches ["foo"],
|
(** [comp / route] matches ["foo/bar/…"] iff [comp] matches ["foo"],
|
||||||
and [route] matches ["bar/…"]. *)
|
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
|
end
|
||||||
|
|
||||||
(** {2 Server} *)
|
(** {2 Server} *)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue