X-Forwarded-For parsing and trusted proxy detection for OCaml
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

ocaml-xff: enable MDX on lib/xff.mli, fix broken doc example

Run mdx on lib/xff.mli so the {[ ... ]} odoc block now type-checks.
The example called Xff.get_client_ip_string -- the real function is
named Xff.client_ip_string -- and referenced an undefined
`socket_addr`.

Replaced the function name with the real one, gave socket_ip a
concrete `Some (Ipaddr.of_string_exn "10.0.0.1")`, and added an
`assert (client_ip = "203.0.113.50")` so the example documents what
the trusted-proxy unwrap returns rather than burying the answer in a
trailing prose comment.

+8 -2
+4
lib/dune
··· 2 2 (name xff) 3 3 (public_name xff) 4 4 (libraries ipaddr fmt)) 5 + 6 + (mdx 7 + (files xff.mli) 8 + (libraries xff ipaddr))
+4 -2
lib/xff.mli
··· 11 11 let trusted = Xff.private_ranges 12 12 13 13 (* Extract client IP from request *) 14 + let socket_ip = Some (Ipaddr.of_string_exn "10.0.0.1") 14 15 let client_ip = 15 - Xff.get_client_ip_string ~socket_ip:(Some socket_addr) 16 + Xff.client_ip_string ~socket_ip 16 17 ~xff_header:(Some "203.0.113.50, 10.0.0.1") 17 18 ~trusted_proxies:(Some trusted) 18 - (* Returns "203.0.113.50" if socket_ip is in trusted range *) 19 + 20 + let () = assert (client_ip = "203.0.113.50") 19 21 ]} 20 22 21 23 {2 References}