Class type Netcgi_types.cgi_activation


class type cgi_activation = object .. end
The common interface of CGI activation objects

method environment : Netcgi_env.cgi_environment
The CGI environment object. This object is the "outer layer" of the activation object that connects it with real I/O channels.
method request_method : request_method
The HTTP method

Initial arguments

Initial arguments are the CGI arguments at the time the arguments were parsed from the environment.

method initial_arguments : (string * cgi_argument) list
The complete list of initial arguments
method initial_argument : string -> cgi_argument
Returns a certain initial argument, or raises Not_found
method initial_argument_value : ?default:string -> string -> string
Returns the value of the initial argument as string. If the argument does not exist, the default is returned. The default defaults to "".
method initial_multiple_argument : string -> cgi_argument list
Returns a certain initial argument that occurs several times in the set of arguments

Current arguments

The current arguments can be modified, but they are initialized to the initial arguments at object creation time:

method arguments : (string * cgi_argument) list
The complete list of current arguments
method argument : string -> cgi_argument
Returns a certain current argument, or raises Not_found
method argument_value : ?default:string -> string -> string
Returns the value of the current argument as string. If the argument does not exist, the default is returned. The default defaults to "".
method multiple_argument : string -> cgi_argument list
Returns a certain current argument that occurs several times in the set of arguments

Modify the set of current arguments

method set_arguments : ?fin:bool -> cgi_argument list -> unit
Replaces the set of current arguments with a new set.
fin : If true, the default, the arguments of the old set that are not member of the new set are finalized
method update_argument : ?fin:bool -> cgi_argument -> unit
The passed argument replaces the current argument (or multiple argument) with the same name; if there is no such argument, the passed argument is added to the list of current args
fin : If true, the default, the replaced arguments are finalized (unless they happen to be the same as the new argument)
method update_multiple_argument : ?fin:bool -> cgi_argument list -> unit
The passed arguments must all have the same name. They replace the current argument (or multiple argument) with the same name; if there is no such argument, the passed arguments are added to the set of current arguments.
fin : If true, the default, the replaced arguments are finalized (unless they happen to be the same as the new arguments)
method delete_argument : ?fin:bool -> string -> unit
Deletes all arguments with the passed name.
fin : If true, the default, the deleted arguments are finalized

Self-referencing URL

method url : ?protocol:Netcgi_env.protocol ->
?with_authority:other_url_spec ->
?with_script_name:other_url_spec ->
?with_path_info:other_url_spec ->
?with_query_string:query_string_spec -> unit -> string
Returns the URL of the current CGI activation.


Generating Output

method output : Netchannels.trans_out_obj_channel
The output channel to which the generated content is intended to be written.

The output channel may have transactional semantics, and because of this, it is an trans_out_obj_channel. Implementations are free to support transactions or not.

After all data have been written, the method commit_work must be called, even if there is no support for transactions.

Simple Example:

 cgi # output # output_string "Hello world!\n";
 cgi # output # commit_work()
 

Example for an error handler and a transaction buffer: If an error happens, it is possible to roll the channel back, and to write the error message.

 try
   cgi # set_header ... ();
   cgi # output # output_string "Hello World!"; ...
   cgi # output # commit_work();
 with
   err ->
     cgi # output # rollback_work();
     cgi # set_header ... ();
     cgi # output # output_string "Software error!"; ...
     cgi # output # commit_work();
 

method set_header : ?status:status ->
?content_type:string ->
?cache:cache_control ->
?filename:string ->
?language:string ->
?script_type:string ->
?style_type:string ->
?set_cookie:cgi_cookie list ->
?fields:(string * string list) list -> unit -> unit
Sets the header.

When the output channel supports transactions, it is possible to set the header until the channel is commited for the first time. When there is no support for transactions, the header must be set before the first byte of output is written.

If set_header is called several times, all of the header fields are overwritten.


method set_redirection_header : string -> unit
Sets the header such that a redirection to the specified URL is performed. If the URL begins with "http:" the redirection directive is passed back to the client, and the client will repeat the request for the new location. If the URL begins with "/", the server performs the redirection, and it is invisible for the client.

Cleaning Up

method finalize : unit -> unit
This method calls finalize for every CGI argument to ensure that all files are deleted. It does not close the in/out channels, however. This method is not registered in the garbage collector, and it is a bad idea to do so.