# Module Netcgi

    module Netcgi: sig .. end

Classical CGI implementation

For in introduction, see the guide "Introduction into OcamlNet".

Classical CGI implementation

For in introduction, see the guide "Introduction into OcamlNet".

    class simple_argument : ?ro:bool -> string -> string -> Netcgi_types.cgi_argument

`new simple_argument name value`: Creates an unstructured CGI argument called `name` with contents `value`.

    class mime_argument : ?work_around_backslash_bug:bool -> string -> Netmime.mime_message -> Netcgi_types.cgi_argument

`new mime_argument name msg`: Creates a MIME-structured CGI argument called `name` with contents `msg`.

    type argument_processing = [ `Automatic | `File | `Memory ]

How to process CGI arguments:

- ``Memory`: Keep the value of the argument in memory
- ``File`: Store the value of the argument in an external file
- ``Automatic`: If the argument is structured and carries a file name, the value will be stored in a file; otherwise it is loaded into memory. (Note: The meaning of ``Automatic` changed in OcamlNet 0.92.)

    type operating_type = [ `Direct of string
           | `Transactional of
               Netcgi_env.cgi_config ->
               Netchannels.out_obj_channel -> Netchannels.trans_out_obj_channel ]

The operating type determines how generated data are buffered.

- ``Direct sep`: Data written to the output channel of the activation object is not collected in a transaction buffer, but directly sent to the browser (the normal I/O buffering is still active, however, so call `flush` to ensure data are really sent). The method `commit_work` of the output channel is the same as `flush`. The method `rollback_work` causes that the string `sep` is sent, meant as a separator between the already generated output, and the now following error message.
- ``Transactional f`: A transactional channel `tc` is created from the real output channel `ch` by calling `f cfg ch` (here, `cfg` is the CGI configuration). The channel `tc` is propagated as the output channel of the activation object. This means that the methods `commit_work` and `rollback_work` are implemented by `tc`, and the intended behaviour is that data is buffered in a special transaction buffer until `commit_work` is called. This invocation forces the buffered data to be sent to the browser. If, however, `rollback_work` is called, the buffer is cleared.

Two important examples for ``Transactional`:

- ``Transactional(fun cfg ch -> new Netchannels.buffered_output_channel ch)`: The transaction buffer is implemented in memory
- ``Transactional(fun cfg ch -> new Netchannels.tempfile_output_channel ch)`: The transaction buffer is implemented as an external file

    class std_activation : ?env:Netcgi_env.cgi_environment -> ?processing:string -> Netmime.mime_header -> argument_processing -> ?operating_type:operating_type -> unit -> Netcgi_types.cgi_activation

This class is an implementation of classical CGI.

    val buffered_transactional_optype : operating_type

A predefined transactional `operating_type` using a `Buffer.t` to store the not yet completed transaction.

    val tempfile_transactional_optype : operating_type

A predefined transactional `operating_type` using a temporary file to store the not yet completed transaction

    class custom_activation : ?env:Netcgi_env.cgi_environment -> ?args:Netcgi_types.cgi_argument list -> ?meth:Netcgi_types.request_method -> ?operating_type:operating_type -> unit -> Netcgi_types.cgi_activation

This class can be used to implement a non-standard connector that has the same output format as CGI.