module Extensions: sig
.. end
Writing extensions for Ocsigen
exception Ocsigen_http_error of int
exception Ocsigen_Is_a_directory
exception Ocsigen_malformed_url
exception Ocsigen_Internal_Error of string
exception Bad_config_tag_for_extension of string
Try next extension
exception Error_in_config_file of string
Stop with an error message
type
url_path = string list
The type of URL paths. ["plop";"plip"]
corresponds to plop/plip
.
val string_of_url_path : url_path -> string
type
virtual_host_part =
| |
Text of string * int |
| |
Wildcard |
type
virtual_hosts = (virtual_host_part list * int option) list
type
file_info = {
|
tmp_filename : string ; |
|
filesize : int64 ; |
|
original_filename : string ; |
}
The files sent in the request
Note that the files are cancelled once the request has been fulfilled
type
request_info = {
|
ri_url_string : string ; |
|
ri_url : Neturl.url ; |
|
ri_method : Http_frame.Http_header.http_method ; |
|
ri_protocol : Http_frame.Http_header.proto ; |
|
ri_path_string : string ; |
|
ri_full_path : string list ; |
|
ri_sub_path : string list ; |
|
ri_sub_path_string : string Lazy.t ; |
|
ri_get_params_string : string option ; |
|
ri_host : string option ; |
|
ri_get_params : (string * string) list Lazy.t ; |
|
ri_post_params : (string * string) list Lwt.t Lazy.t ; |
|
ri_files : (string * file_info) list Lwt.t Lazy.t ; |
|
ri_inet_addr : Unix.inet_addr ; |
|
ri_ip : string ; |
|
ri_ip32 : int32 Lazy.t ; |
|
ri_remote_port : int ; |
|
ri_port : int ; |
|
ri_user_agent : string ; |
|
ri_cookies_string : string option Lazy.t ; |
|
ri_cookies : string Http_frame.Cookievalues.t Lazy.t ; |
|
ri_ifmodifiedsince : float option ; |
|
ri_ifunmodifiedsince : float option ; |
|
ri_ifnonematch : string list ; |
|
ri_ifmatch : string list option ; |
|
ri_content_type : string option ; |
|
ri_content_length : int64 option ; |
|
ri_referer : string option Lazy.t ; |
|
ri_accept : ((string option * string option) * float option * (string * string) list) list Lazy.t ; |
|
ri_accept_charset : (string option * float option) list Lazy.t ; |
|
ri_accept_encoding : (string option * float option) list Lazy.t ; |
|
ri_accept_language : (string * float option) list Lazy.t ; |
|
ri_http_frame : Http_frame.t ; |
|
ri_extension_info : exn list ; |
}
The request
If you force ri_files
or ri_post_params
, the request is fully read,
so it is not possible any more to read it from ri_http_frame
(and vice versa).
type
answer =
type
extension =
val register_extension : (virtual_hosts ->
url_path ->
string option -> Simplexmlparser.xml -> extension) *
(unit -> unit) * (unit -> unit) * (exn -> string) -> unit
For each extension generating pages, we register four functions:
- a function taking
- the name of the virtual <host>
that will be called for each <host>,
and that will generate a function taking:
- the path attribute of a <site> tag
that will be called for each <site>,
and that will generate a function taking:
- an item of the config file
that will be called on each tag inside <site> and:
- raise
Bad_config_tag_for_extension
if it does not recognize that tag
- return something of type
extension
(filter or page generator)
- a function that will be called at the beginning
of the initialisation phase (each time the config file is reloaded)
(Note that the extensions are not reloaded)
- a function that will be called at the end of the initialisation phase
of the server
- a function that will create an error message from the exceptions
that may be raised during the initialisation phase, and raise again
all other exceptions
val get_config : unit -> Simplexmlparser.xml list
While loading an extension,
get the configuration tree between <dynlink></dynlink>
val ri_of_url : string -> request_info -> request_info
Parsing URLs.
This allows to modify the URL in the request_info.
(to be used for example with Ext_retry_with or Ext_continue_with)