29
29
open Ocsigen_headers
32
let gen (header, regexp, dest) charset = function
32
let gen (header, regexp, dest) = function
33
33
| Req_not_found (code,_) -> return (Ext_next code)
34
| Req_found (ri, result) ->
35
result () >>= fun res ->
34
| Req_found (ri, res) ->
37
36
let header_values =
38
37
Http_headers.find_all header res.Ocsigen_http_frame.res_headers
61
60
Lwt.return (Ocsigen_extensions.Ext_found (fun () -> Lwt.return res))
63
(*****************************************************************************)
64
(** Function to be called at the beginning of the initialisation phase
65
of the server (actually each time the config file is reloaded) *)
69
(** Function to be called at the end of the initialisation phase *)
75
(*****************************************************************************)
76
(** A function that will create an error message from the exceptions
77
that may be raised during the initialisation phase, and raise again
78
all other exceptions. That function has type exn -> string. Use the
79
raise function if you don't need any. *)
80
let exn_handler = raise
84
(*****************************************************************************)
85
(** Extensions may define new tags for configuring each site.
86
These tags are inside <site ...>...</site> in the config file.
90
<extensiontemplate module=".../mymodule.cmo" />
93
Each extension will set its own configuration options, for example:
95
<extensiontemplate module=".../mymodule.cmo" />
96
<eliom module=".../myeliommodule.cmo" />
97
<static dir="/var/www/plop" />
102
let parse_config path charset _ _ = function
64
(*****************************************************************************)
66
let parse_config = function
103
67
| Element ("outputfilter", atts, []) ->
104
68
let rec parse_attrs ((h, r, d) as res) = function
114
78
(match parse_attrs (None, None, None) atts with
115
79
| (Some h, Some r, Some d) ->
116
gen (Http_headers.name h, r, d) charset
80
gen (Http_headers.name h, r, d)
119
83
(Error_in_config_file
120
84
"Missing attributes for <outputfilter header=... regexp=... dest=... />"))
85
| Element ("outputfilter" as s, _, _) -> badconfig "Bad syntax for tag %s" s
121
87
| Element (t, _, _) -> raise (Bad_config_tag_for_extension t)
123
89
raise (Error_in_config_file "Unexpected data in config file")
128
(*****************************************************************************)
129
let site_creator hostpattern = parse_config
130
(* hostpattern has type Ocsigen_extensions.virtual_hosts
131
and represents the name of the virtual host *)
134
95
(*****************************************************************************)
135
96
(** Registration of the extension *)
136
let _ = Ocsigen_extensions.register_extension
97
let () = register_extension
99
~fun_site:(fun _ _ _ _ -> parse_config)
100
~user_fun_site:(fun _ _ _ _ _ -> parse_config)