@@ -48,12 +48,18 @@ let make_uri u =
4848 and u_get_params_flat = lazy (flatten_get_params (Lazy. force u_get_params)) in
4949 {u_uri; u_get_params; u_get_params_flat; u_path; u_path_string}
5050
51+ type client_conn =
52+ [ `Inet of Ipaddr .t * int
53+ | `Unix of string
54+ | `Forwarded_for of string
55+ | `Unknown ]
56+
5157type t =
5258 { r_address : Ocsigen_config.Socket_type .t
5359 ; r_port : int
5460 ; r_ssl : bool
5561 ; r_filenames : string list ref
56- ; r_remote_ip : string
62+ ; r_client_conn : client_conn
5763 ; r_forward_ip : string list
5864 ; r_uri : uri
5965 ; r_meth : Cohttp.Code .meth
@@ -79,7 +85,7 @@ let make
7985 ~port
8086 ~ssl
8187 ~filenames
82- ~sockaddr
88+ ~client_conn
8389 ~body
8490 ~connection_closed
8591 request
@@ -88,7 +94,7 @@ let make
8894 ; r_port = port
8995 ; r_ssl = ssl
9096 ; r_filenames = filenames
91- ; r_remote_ip = sockaddr
97+ ; r_client_conn = client_conn
9298 ; r_forward_ip = forward_ip
9399 ; r_uri = make_uri (Cohttp.Request. uri request)
94100 ; r_encoding = Cohttp.Request. encoding request
@@ -110,7 +116,7 @@ let path {r_uri = {u_path; _}; _} = Lazy.force u_path
110116let update
111117 ?ssl
112118 ?forward_ip
113- ?remote_ip
119+ ?client_conn
114120 ?sub_path
115121 ?meth
116122 ?get_params_flat
@@ -122,7 +128,7 @@ let update
122128 ; r_uri = {u_uri; _} as r_uri
123129 ; r_meth
124130 ; r_forward_ip
125- ; r_remote_ip
131+ ; r_client_conn
126132 ; r_cookies_override
127133 ; r_body
128134 ; r_sub_path
@@ -132,8 +138,8 @@ let update
132138 let r_ssl = match ssl with Some ssl -> ssl | None -> r_ssl
133139 and r_forward_ip =
134140 match forward_ip with Some forward_ip -> forward_ip | None -> r_forward_ip
135- and r_remote_ip =
136- match remote_ip with Some remote_ip -> remote_ip | None -> r_remote_ip
141+ and r_client_conn =
142+ match client_conn with Some c -> c | None -> r_client_conn
137143 and r_sub_path = match sub_path with Some _ -> sub_path | None -> r_sub_path
138144 and r_body =
139145 match post_data with
@@ -171,7 +177,7 @@ let update
171177 ; r_uri
172178 ; r_meth
173179 ; r_forward_ip
174- ; r_remote_ip
180+ ; r_client_conn
175181 ; r_body
176182 ; r_cookies_override
177183 ; r_sub_path
@@ -270,18 +276,14 @@ let post_params r s i =
270276let files r s i =
271277 match force_post_data r s i with Some v -> Some (v > |= snd) | None -> None
272278
273- let remote_ip {r_remote_ip ; _} = r_remote_ip
279+ let client_conn { r_client_conn = c ; _} = c
274280
275- let remote_ip_parsed {r_remote_ip; _} =
276- let is_prefix prefix s =
277- (* TODO: Naive version to be swapped with [String.starts_with ~prefix s]
278- when the dependency on OCaml >= 4.13 is acceptable. *)
279- let plen = String. length prefix in
280- String. length s > = plen && String. sub s 0 plen = prefix
281- in
282- if is_prefix " unix://" r_remote_ip
283- then `Unix r_remote_ip
284- else `Ip (Ipaddr. of_string_exn r_remote_ip)
281+ let client_conn_to_string {r_client_conn = c ; _} =
282+ match c with
283+ | `Inet (ip , _ ) -> Ipaddr. to_string ip
284+ | `Unix path -> " unix:" ^ path
285+ | `Forwarded_for ip -> " forwarded:" ^ ip
286+ | `Unknown -> " unknown"
285287
286288let forward_ip {r_forward_ip; _} = r_forward_ip
287289let request_cache {r_request_cache; _} = r_request_cache
0 commit comments