23
23
open Ocsigen_lib
24
24
open Xml
25
25
26
- let section = Lwt_log.Section. make " ocsigen:ext:access-control"
26
+ let section = Logs.Src. create " ocsigen:ext:access-control"
27
27
28
28
type condition = Ocsigen_request .t -> bool
29
29
@@ -41,30 +41,28 @@ let ip s =
41
41
let r = Ipaddr.Prefix. mem (Ocsigen_request. remote_ip_parsed ri) prefix in
42
42
if r
43
43
then
44
- Lwt_log. ign_info_f ~section " IP: %a matches %s"
45
- (fun () -> Ocsigen_request. remote_ip)
46
- ri s
44
+ Logs. info ~src: section (fun fmt ->
45
+ fmt " IP: %s matches %s" (Ocsigen_request. remote_ip ri) s)
47
46
else
48
- Lwt_log. ign_info_f ~section " IP: %a does not match %s"
49
- (fun () -> Ocsigen_request. remote_ip)
50
- ri s;
47
+ Logs. info ~src: section (fun fmt ->
48
+ fmt " IP: %s does not match %s" (Ocsigen_request. remote_ip ri) s);
51
49
r
52
50
53
51
let port port ri =
54
52
let r = Ocsigen_request. port ri = port in
55
53
if r
56
- then Lwt_log. ign_info_f ~ section " PORT = %d: true" port
54
+ then Logs. info ~src: section ( fun fmt -> fmt " PORT = %d: true" port)
57
55
else
58
- Lwt_log. ign_info_f ~ section " PORT = %d: false (it is %a) " port
59
- ( fun () ri -> string_of_int ( Ocsigen_request. port ri))
60
- ri ;
56
+ Logs. info ~src: section ( fun fmt ->
57
+ fmt " PORT = %d: false (it is %s) " port
58
+ (string_of_int ( Ocsigen_request. port ri))) ;
61
59
r
62
60
63
61
let ssl ri =
64
62
let r = Ocsigen_request. ssl ri in
65
63
if r
66
- then Lwt_log. ign_info ~ section " SSL: true"
67
- else Lwt_log. ign_info ~ section " SSL: false" ;
64
+ then Logs. info ~src: section ( fun fmt -> fmt " SSL: true" )
65
+ else Logs. info ~src: section ( fun fmt -> fmt " SSL: false" ) ;
68
66
r
69
67
70
68
let header ~name ~regexp :re =
@@ -79,12 +77,15 @@ let header ~name ~regexp:re =
79
77
List. exists
80
78
(fun a ->
81
79
let r = Netstring_pcre. string_match regexp a 0 <> None in
82
- if r then Lwt_log. ign_info_f " HEADER: header %s matches %S" name re;
80
+ if r
81
+ then
82
+ Logs. info (fun fmt -> fmt " HEADER: header %s matches %S" name re);
83
83
r)
84
84
(Ocsigen_request. header_multi ri (Ocsigen_header.Name. of_string name))
85
85
in
86
86
if not r
87
- then Lwt_log. ign_info_f " HEADER: header %s does not match %S" name re;
87
+ then
88
+ Logs. info (fun fmt -> fmt " HEADER: header %s does not match %S" name re);
88
89
r
89
90
90
91
let method_ m ri =
@@ -93,8 +94,9 @@ let method_ m ri =
93
94
let s' = Cohttp.Code. string_of_method m' in
94
95
let r = m = m' in
95
96
if r
96
- then Lwt_log. ign_info_f ~section " METHOD: %s matches %s" s' s
97
- else Lwt_log. ign_info_f ~section " METHOD: %s does not match %s" s' s;
97
+ then Logs. info ~src: section (fun fmt -> fmt " METHOD: %s matches %s" s' s)
98
+ else
99
+ Logs. info ~src: section (fun fmt -> fmt " METHOD: %s does not match %s" s' s);
98
100
r
99
101
100
102
let protocol v ri =
@@ -103,8 +105,10 @@ let protocol v ri =
103
105
let s' = Cohttp.Code. string_of_version v' in
104
106
let r = v = v' in
105
107
if r
106
- then Lwt_log. ign_info_f ~section " PROTOCOL: %s matches %s" s' s
107
- else Lwt_log. ign_info_f ~section " PROTOCOL: %s does not match %s" s' s;
108
+ then Logs. info ~src: section (fun fmt -> fmt " PROTOCOL: %s matches %s" s' s)
109
+ else
110
+ Logs. info ~src: section (fun fmt ->
111
+ fmt " PROTOCOL: %s does not match %s" s' s);
108
112
r
109
113
110
114
let path ~regexp :s =
@@ -118,8 +122,10 @@ let path ~regexp:s =
118
122
let sps = Ocsigen_request. sub_path_string ri in
119
123
let r = Netstring_pcre. string_match regexp sps 0 <> None in
120
124
if r
121
- then Lwt_log. ign_info_f ~section " PATH: \" %s\" matches %S" sps s
122
- else Lwt_log. ign_info_f ~section " PATH: \" %s\" does not match %S" sps s;
125
+ then Logs. info ~src: section (fun fmt -> fmt " PATH: \" %s\" matches %S" sps s)
126
+ else
127
+ Logs. info ~src: section (fun fmt ->
128
+ fmt " PATH: \" %s\" does not match %S" sps s);
123
129
r
124
130
125
131
let and_ sub ri = List. for_all (fun cond -> cond ri) sub
@@ -167,8 +173,12 @@ let rec parse_condition = function
167
173
let sps = Ocsigen_request. sub_path_string ri in
168
174
let r = Netstring_pcre. string_match regexp sps 0 <> None in
169
175
if r
170
- then Lwt_log. ign_info_f ~section " PATH: \" %s\" matches %S" sps s
171
- else Lwt_log. ign_info_f ~section " PATH: \" %s\" does not match %S" sps s;
176
+ then
177
+ Logs. info ~src: section (fun fmt ->
178
+ fmt " PATH: \" %s\" matches %S" sps s)
179
+ else
180
+ Logs. info ~src: section (fun fmt ->
181
+ fmt " PATH: \" %s\" does not match %S" sps s);
172
182
r
173
183
| Element (("path" as s ), _ , _ ) ->
174
184
Ocsigen_extensions. badconfig " Bad syntax for tag %s" s
@@ -192,11 +202,11 @@ let rec parse_condition = function
192
202
(* ****************************************************************************)
193
203
(* Parsing filters *)
194
204
195
- let comma_space_regexp = Netstring_pcre. regexp " \ *,\ *"
205
+ let comma_space_regexp = Netstring_pcre. regexp " *, *"
196
206
197
207
let allow_forward_for_handler ?(check_equal_ip = false ) () =
198
208
let apply ({Ocsigen_extensions. request_info; _} as request ) code =
199
- Lwt_log. ign_info ~ section " Allowed proxy" ;
209
+ Logs. info ~src: section ( fun fmt -> fmt " Allowed proxy" ) ;
200
210
let request =
201
211
let header =
202
212
Ocsigen_request. header request_info Ocsigen_header.Name. x_forwarded_for
@@ -218,14 +228,15 @@ let allow_forward_for_handler ?(check_equal_ip = false) () =
218
228
~remote_ip: original_ip request_info }
219
229
else (
220
230
(* the announced ip of the proxy is not its real ip *)
221
- Lwt_log. ign_warning_f ~section
222
- " X-Forwarded-For: host ip (%s) does not match the header (%s)"
223
- (Ocsigen_request. remote_ip request_info)
224
- header;
231
+ Logs. warn ~src: section (fun fmt ->
232
+ fmt
233
+ " X-Forwarded-For: host ip (%s) does not match the header (%s)"
234
+ (Ocsigen_request. remote_ip request_info)
235
+ header);
225
236
request)
226
237
| _ ->
227
- Lwt_log. ign_info_f ~ section " Malformed X-Forwarded-For field: %s "
228
- header;
238
+ Logs. info ~src: section ( fun fmt ->
239
+ fmt " Malformed X-Forwarded-For field: %s " header) ;
229
240
request)
230
241
| None -> request
231
242
in
@@ -240,7 +251,7 @@ let allow_forward_for_handler ?(check_equal_ip = false) () =
240
251
241
252
let allow_forward_proto_handler =
242
253
let apply ({Ocsigen_extensions. request_info; _} as request ) code =
243
- Lwt_log. ign_info ~ section " Allowed proxy for ssl" ;
254
+ Logs. info ~src: section ( fun fmt -> fmt " Allowed proxy for ssl" ) ;
244
255
let request_info =
245
256
let header =
246
257
Ocsigen_request. header request_info
@@ -252,8 +263,8 @@ let allow_forward_proto_handler =
252
263
| "http" -> Ocsigen_request. update ~ssl: false request_info
253
264
| "https" -> Ocsigen_request. update ~ssl: true request_info
254
265
| _ ->
255
- Lwt_log. ign_info_f ~ section " Malformed X-Forwarded-Proto field: %s "
256
- header;
266
+ Logs. info ~src: section ( fun fmt ->
267
+ fmt " Malformed X-Forwarded-Proto field: %s " header) ;
257
268
request_info)
258
269
| None -> request_info
259
270
in
@@ -292,17 +303,19 @@ let parse_config parse_fun = function
292
303
Lwt. return
293
304
(if condition ri.Ocsigen_extensions. request_info
294
305
then (
295
- Lwt_log. ign_info ~section " COND: going into <then> branch" ;
306
+ Logs. info ~src: section (fun fmt ->
307
+ fmt " COND: going into <then> branch" );
296
308
Ocsigen_extensions. Ext_sub_result ithen)
297
309
else (
298
- Lwt_log. ign_info ~ section
299
- " COND: going into <else> branch, if any" ;
310
+ Logs. info ~src: section ( fun fmt ->
311
+ fmt " COND: going into <else> branch, if any" ) ;
300
312
Ocsigen_extensions. Ext_sub_result ielse)))
301
313
| Element (("if" as s ), _ , _ ) ->
302
314
Ocsigen_extensions. badconfig " Bad syntax for tag %s" s
303
315
| Element ("notfound" , [] , [] ) ->
304
316
fun _rs ->
305
- Lwt_log. ign_info ~section " NOT_FOUND: taking in charge 404" ;
317
+ Logs. info ~src: section (fun fmt ->
318
+ fmt " NOT_FOUND: taking in charge 404" );
306
319
Lwt. return
307
320
(Ocsigen_extensions. Ext_stop_all (Ocsigen_cookie_map. empty, `Not_found ))
308
321
| Element (("notfound" as s ), _ , _ ) ->
@@ -340,7 +353,8 @@ let parse_config parse_fun = function
340
353
Ocsigen_extensions. badconfig " Bad syntax for tag %s" s
341
354
| Xml. Element ("forbidden" , [] , [] ) ->
342
355
fun _rs ->
343
- Lwt_log. ign_info ~section " FORBIDDEN: taking in charge 403" ;
356
+ Logs. info ~src: section (fun fmt ->
357
+ fmt " FORBIDDEN: taking in charge 403" );
344
358
Lwt. return
345
359
(Ocsigen_extensions. Ext_stop_all (Ocsigen_cookie_map. empty, `Forbidden ))
346
360
| Element (("forbidden" as s ), _ , _ ) ->
0 commit comments