Ocamlnet 3 Reference Manual : Netcgi.cgi_environment

# Class type Netcgi.cgi_environment

    class type cgi_environment = object .. end

The environment of a request consists of the information available besides the data sent by the user (as key-value pairs).

### CGI properties

The following properties are standardised by CGI. The methods return `""` (or `None` in the case of the port number) when the property is not available.

    method cgi_gateway_interface : string

    method cgi_server_name : string

    method cgi_server_port : int option

    method cgi_server_protocol : string

    method cgi_server_software : string

    method cgi_request_method : string

We recommend you to use the method `Netcgi.cgi.request_method` which is more type-safe and informative.

    method cgi_script_name : string

    method cgi_path_info : string

    method cgi_path_translated : string

    method cgi_auth_type : string

    method cgi_remote_addr : string

    method cgi_remote_host : string

    method cgi_remote_user : string

    method cgi_remote_ident : string

    method cgi_query_string : string

This is the row query string. The `Netcgi.cgi` class gives you an easy access to the arguments through the `#arg...` methods.

    method protocol : Nethttp.protocol

The server protocol in a decoded form. It can be either

- ``Http((major,minor),attributes)` or
- ``Other`.

    method cgi_property : ?default:string -> string -> string

Returns a (possibly non-standard) CGI environment property. If the property is not set, `Not_found` is be raised unless the `default` argument is passed. The `default` argument determines the result of the function in this case.

The method takes the case-sensitive name and returns the value of the property. Usually, these properties have uppercase names.

For example, `cgi_gateway_interface` returns the same as

            cgi_property ~default:"" "GATEWAY_INTERFACE"

You cannot access the fields coming from the HTTP header. Use the method `input_header_field` instead.

    method cgi_properties : (string * string) list

Return all properties as an associative list.

    method cgi_https : bool

A well-known extension is the HTTPS property. It indicates whether a secure connection is used (SSL/TLS). This method interprets this property and returns true if the connection is secure. This method fails if there is a HTTPS property with an unknown value.

### Header of the incoming HTTP request.

    method input_header : Netmime.mime_header

The whole HTTP header.

    method input_header_field : ?default:string -> string -> string

`#input_header_field ?default f` returns the value of a field `f` of the HTTP request header. The field name `f` is case-insensitive; if the name is a compound name, the parts are separated by "-", e.g. `"content-length"`. If there are several fields with the same name only the first field will be returned.
Raises `Not_found` if the field does not exist, unless the `default` argument is passed. The `default` argument is the result of the function in this case.

    method multiple_input_header_field : string -> string list

Returns the values of all fields with the passed name of the request header.

    method input_header_fields : (string * string) list

Returns the input header as (name,value) pairs. The names may consist of lowercase or uppercase letters.

    method cookie : string -> Cookie.t

`#cookie cn` returns the cookie with name `cn`.
Raises `Not_found` if such a cookie does not exists.

    method cookies : Cookie.t list

Returns the list of valid cookies found in the request header. Here "valid" means that the decode function does not raise an exception.

    method user_agent : string

This is a convenience method that returns the `"User-agent"` field of the HTTP request header.

    method input_content_length : int

Returns the `"Content-length"` request header field.
Raises `Not_found` if it is not set.

    method input_content_type_string : string

Returns the `"Content-type"` request header field as a plain string or `""` if it is not set.

    method input_content_type : unit -> string * (string * Mimestring.s_param) list

Returns the parsed `"Content-type"` request header field.
Raises `Not_found` if it is not set. See also `Mimestring.scan_mime_type_ep`.

### Response header

    method output_header : Netmime.mime_header

The whole HTTP response header

    method output_header_field : ?default:string -> string -> string

Returns the value of a field of the response header. If the field does not exist, `Not_found` will be raised unless the `default` argument is passed. The `default` argument determines the result of the function in this case.

If there are several fields with the same name only the first field will be returned.

The anonymous string is the name of the field. The name is case-insensitive, and it does not matter whether it consists of lowercase or uppercase letters. If the name is a compound name, the parts are separated by "-", e.g. `"content-length"`.

    method multiple_output_header_field : string -> string list

Returns the values of all fields with the passed name of the repsonse header.

    method output_header_fields : (string * string) list

Returns the output header as (name,value) pairs. The names may consist of lowercase or uppercase letters.

    method set_output_header_field : string -> string -> unit

Sets the value of a field of the response header. The previous value, if any, is overwritten. If there have been multiple values, all values will be removed and replaced by the single new value.

    method set_multiple_output_header_field : string -> string list -> unit

Sets multiple values of a field of the response header. Any previous values are removed and replaced by the new values.

    method set_output_header_fields : (string * string) list -> unit

Sets the complete response header at once.

    method set_status : Nethttp.http_status -> unit

Sets the response status. This is by definition the same as setting the `Status` output header field.

    method send_output_header : unit -> unit

This method will encode and send the output header to the output channel. Note that of the output_channel is ``Transactionnal` (as opposed to ``Direct`), no output will actually take place before you issue `#commit_work()` -- thus a `#rollback_work()` will also rollback the headers as expected.

### The output channel transferring the response

    method output_ch : Netchannels.out_obj_channel

Deprecated.Use `#out_channel` instead.

    method out_channel : Netchannels.out_obj_channel

The "raw" output channel. In general you should use instead `Netcgi.cgi``#out_channnel` which supports transactions (if you choose to). Access to the "raw" channel is useful however, for example for sending images or download of files (for which transactions are not interesting but merely more work).

### Logging

    method log_error : string -> unit

`#log_error msg` appends `msg` to the webserver log.

### Miscellaneous

    method config : config

The configuration of the request.