@@ -48,14 +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_sockaddr : Lwt_unix .sockaddr
57- ; r_remote_ip : string Lazy .t
58- ; r_remote_ip_parsed : [`Ip of Ipaddr .t | `Unix of string ] Lazy .t
62+ ; r_client_conn : client_conn
5963 ; r_forward_ip : string list
6064 ; r_uri : uri
6165 ; r_meth : Cohttp.Code .meth
@@ -81,31 +85,16 @@ let make
8185 ~port
8286 ~ssl
8387 ~filenames
84- ~sockaddr
88+ ~client_conn
8589 ~body
8690 ~connection_closed
8791 request
8892 =
89- let r_remote_ip =
90- lazy
91- (match sockaddr with
92- | Unix. ADDR_INET (ip , _port ) -> Unix. string_of_inet_addr ip
93- | ADDR_UNIX f -> f)
94- in
95- let r_remote_ip_parsed =
96- lazy
97- (match sockaddr with
98- | Unix. ADDR_INET (ip , _port ) ->
99- `Ip (Ipaddr. of_string_exn (Unix. string_of_inet_addr ip))
100- | ADDR_UNIX f -> `Unix f)
101- in
10293 { r_address = address
10394 ; r_port = port
10495 ; r_ssl = ssl
10596 ; r_filenames = filenames
106- ; r_sockaddr = sockaddr
107- ; r_remote_ip
108- ; r_remote_ip_parsed
97+ ; r_client_conn = client_conn
10998 ; r_forward_ip = forward_ip
11099 ; r_uri = make_uri (Cohttp.Request. uri request)
111100 ; r_encoding = Cohttp.Request. encoding request
@@ -127,7 +116,7 @@ let path {r_uri = {u_path; _}; _} = Lazy.force u_path
127116let update
128117 ?ssl
129118 ?forward_ip
130- ?remote_ip
119+ ?client_conn
131120 ?sub_path
132121 ?meth
133122 ?get_params_flat
@@ -139,8 +128,7 @@ let update
139128 ; r_uri = {u_uri; _} as r_uri
140129 ; r_meth
141130 ; r_forward_ip
142- ; r_remote_ip
143- ; r_remote_ip_parsed
131+ ; r_client_conn
144132 ; r_cookies_override
145133 ; r_body
146134 ; r_sub_path
@@ -150,11 +138,8 @@ let update
150138 let r_ssl = match ssl with Some ssl -> ssl | None -> r_ssl
151139 and r_forward_ip =
152140 match forward_ip with Some forward_ip -> forward_ip | None -> r_forward_ip
153- and r_remote_ip, r_remote_ip_parsed =
154- match remote_ip with
155- | Some remote_ip ->
156- lazy remote_ip, lazy (`Ip (Ipaddr. of_string_exn remote_ip))
157- | None -> r_remote_ip, r_remote_ip_parsed
141+ and r_client_conn =
142+ match client_conn with Some c -> c | None -> r_client_conn
158143 and r_sub_path = match sub_path with Some _ -> sub_path | None -> r_sub_path
159144 and r_body =
160145 match post_data with
@@ -192,8 +177,7 @@ let update
192177 ; r_uri
193178 ; r_meth
194179 ; r_forward_ip
195- ; r_remote_ip
196- ; r_remote_ip_parsed
180+ ; r_client_conn
197181 ; r_body
198182 ; r_cookies_override
199183 ; r_sub_path
@@ -292,8 +276,15 @@ let post_params r s i =
292276let files r s i =
293277 match force_post_data r s i with Some v -> Some (v > |= snd) | None -> None
294278
295- let remote_ip {r_remote_ip; _} = Lazy. force r_remote_ip
296- let remote_ip_parsed {r_remote_ip_parsed; _} = Lazy. force r_remote_ip_parsed
279+ let client_conn {r_client_conn = c ; _} = c
280+
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"
287+
297288let forward_ip {r_forward_ip; _} = r_forward_ip
298289let request_cache {r_request_cache; _} = r_request_cache
299290let tries {r_tries; _} = r_tries
0 commit comments