# 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.

- `protocol`: The URL scheme. By default, the URL scheme is used that is described in the environment
- `with_authority`: Whether to include authority part of the URL, and if yes, from which source. Default: ``Env`
- `with_script_name`: Whether to include the part of the URL path identifying the CGI script, and if yes, from which source. Default: ``Env`
- `with_path_info`: Whether to include the rest of the URL path exceeding the script name, and if yes, from which source. Default: ``Env`
- `with_query_string`: Whether to include the query string, and if yes, which one. Default: ``None`, i.e. no query string

## 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.

- `status`: Sets the HTTP status of the reply. Defaults to "no status", but the server normally complements an ``Ok` status in this case
- `content_type`: Sets the content type. Defaults to "text/html" if the content type is not yet set.
- `cache`: Sets the cache behavior for replies to GET requests. The default is ``Unspecified`. It is strongly recommended to specify the caching behaviour!!! You are on the safe side with ``No_cache`, forcing every page to be regenerated. If your data do not change frequently, ``Max_age n` tells the caches to store the data at most `n` seconds.
- `filename`: Sets the filename associated with the page. This filename is taken for the "save as..." dialog. Default: no filename. Note: It is bad practice if the filename contains problematic characters (backslash, double quote, space), or the names of directories
- `script_type`: Sets the language of the script tag (for HTML replies). It is recommended to use this field if there are `ONXXX` attributes containing scripts before the first `<SCRIPT>` element, because you cannot specify the script language for the `ONXXX` attributes otherwise. `script_type` must be a media type, e.g. "text/javascript". Default: no language is specified.
- `style_type`: Sets the language of the style tag (for HTML replies). It is recommended to use this field if there are `STYLE` attributes containing scripts before the first `<STYLE>` element, because you cannot specify the style language for the `STYLE` attributes otherwise. `style_type` must be a media type, e.g. "text/css". Default: no language is specified.
- `set_cookie`: Sets a number of cookies. Default: `[]` You can query the cookies using `environment#cookies`.
- `fields`: Sets other fields of the header.

    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.