Type definitions for the HTTP daemon
Contents
Many types can also be found in the Nethttp
module (part of netstring).
Furthermore, Netcgi_env
and Netcgi_types
are of interest (part of cgi).
Some HTTP containers allow you to raise this exception. The standard
response corresponding to http_status
is sent back to the client.
If the third argument exists, an entry into the error log
is written.
The full request URI. Identical to the CGI property "REQUEST_URI"
Remember this version of cgi_properties
as the one sent to the
config_log_access
function
The input channel for reading the body of the request
so far known, or 0L
so far known, or false
Sends the output header with a file as body. The file must already be open, and positioned where the transmission begins. The number is the length of the transmission.
This method may return immediately when it is possible to open the file, and
to set the kernel up for file transmission. Otherwise a Unix_error
is
raised. It is also allowed that this method blocks until the file is actually
transmitted.
It is not allowed to print to the output channel and to call send_file
.
Only one transmission method must be invoked.
Reflects the state of the output generation:
`Start
: Nothing is generated yet`Sending
: Output is already being sent`End
: The response (for a single request) has been fully sentAn extension of cgi_environment
for use with the daemon. The methods
retrieving the socket addresses are virtual.
Same as v_extended_environment
, but no virtual methods
This class implements an environment with defined internal containers. These containers are empty, but fully functional. The following methods are empty and should be redefined:
send_output_header
send_file
log_error
log_props
The virtual methods, of course, must be defined!
This class overlays the input-side containers of an existing environment.
The output-side containers (out_header
, and out_channel
)
are physically identical with the existing environment.
If one of the argument is not passed on class instantiation, the corresponding overlay container is initialized with the current value of the passed environment. As exception of this rule, the input channel is initialized with an empty input channel.
Outputs the string argument as response body, together with the given status and the header (optional). Response header fields are set as follows:
Content-Length
is set to the length of the string.Content-Type
is set to "text/html" unless given by the header.If the header is not passed, the header of the environment is taken. If the header argument exists, however, it overrides the header of the environment.
Outputs the contents of a file as response body, together with the given status and the header (optional). The string is the file name. The first int64 number is the position in the file where to start, and the second number is the length of the body. Response header fields are set as follows:
Content-Length
is set to the length of the string.Content-Type
is set to "text/html" unless given by the header.Note that Content-Range
is not set automatically, even if the file is only
partially transferred.
If the header is not passed, the header of the environment is taken. If the header argument exists, however, it overrides the header of the environment.
The function raises Sys_error
when the file cannot be read.
The method like GET
. May raise Not_found
The URI of the client request. This is often without the
server designation, i.e. just /path?query
.
May raise Not_found
The distilled CGI properties
The size of the input body. May raise Not_found
The HTTP status code to response
Whether the request body was rejected
The size of the output body.
Creates a full_info
object by adding to a request_info
object
The HTTP status code to response
The error message explaining the detail that went wrong
Outputs a "standard response" for the http_status
. The string argument
is an optional entry into the error log.
If the header is not passed, an empty header is taken. If the header argument exists, this header is taken. The header of the environment is never taken.
Service providers are defined using the three class types:
http_service
: The service provider as such. When a HTTP header has been
received, and the service provider is invoked, it returns an object
fitting to the next class type, http_service_receiver
. This object
is tagged with `Accept_body
; at this point there are also alternate ways
of processing, see below.http_service_receiver
: The task of this object is to receive the request
body. When the body has been completely received, the object is notified,
and returns a third object of type http_service_generator
.http_service_generator
: The task of this object is to generate the
response.An implementor is free to define only one class that satisfies all three class types at once. However, this is only an option.
The three objects reflect three stages of HTTP processing. The stages have made explicit to allow the implementor of services to intercept the points in time when the processing of the next stage begins. Furthermore, in multi-threaded environments it is allowed that the stages are performed in the contexts of different threads.
In addition to the three-stage model there also several faster paths of processing:
`Reject_body
can be used to refuse the acceptance of the request body when
it is already clear that an error response is sent back. This path skips
the stage http_service_receiver
.`Static
can be used to send a constant string back (only to be used
when the string needs not to be computed)`File
can be used to send the contents of a file back (only to be used
when the file already exists)The "early" redirect is only allowed in stage 1 of HTTP processing. The string argument is the new URI path of the request. The header can also be exchanged except the fields that are needed to decode the request body. It is not possible to change the method.
The "late" redirect is only allowed in stage 3 of HTTP processing.
The string argument is the new URI path of the request. The header can also
be exchanged except the fields that are needed to decode the request
body. The method is always changed to GET
.
Third stage of HTTP processing: This method is called when the HTTP request has been completely received, and the response is going to be generated. This method can again be called from a different thread than the previous stages. It is allowed to spend any necessary time to compute the response.
When the method returns, the request processing is finished. No more data is allowed to be written to the output channel past this moment.
The method may raise Standard_response
to generate one of the
standard messages.
Second stage of HTTP processing:
This method is called when the body is expected to be arriving. Note that
the main difference to process_header
is that this method can be
called from a different thread. It is allowed (and expected) that this method
blocks while reading the input. Of course, the input and output
channels of the environment are unlocked, and can be used.
When the method returns, the request processing continues with stage 3. Any body data not read is dropped.
It is allowed that this method generates a response (or part of it), although this should be better done in stage 3.
The method may raise Standard_response
to generate one of the
standard messages.
One way of implementing this method is to instantiate Netcgi.std_activation
.
Indicates the immediate reaction upon an arriving HTTP header:
`Accept_body
is the regular way of processing requests. If necessary,
the client is told to continue sending the rest of the request.`Reject_body
can be used when the body of the request is not needed,
and the response will be negative.`Static
means to send the header and a constant string back as response.
The header is taken from the environment if not explicitly passed,
Note: The Content-Length
header is automatically added. The Content-Type
defaults to "text/html".`File
is similar to this, but the data come from a file. The file
is specified by an absolute pathname. The range of the file is given
by the start position and the length of the range.
The header is taken from the environment if not explicitly passed,
Note: The Content-Length
header is automatically added. The Content-Type
defaults to "text/html".`Std_response
is similar to `Static
, however the body is the standard
text for the status code. If the header is omitted, it is taken as empty.
The third argument is an optional entry into the error log.
Note: The Content-Length
header is automatically added. The Content-Type
defaults to "text/html".The name of the type of the service provider
The definition term
First stage of HTTP processing: This method is called when the HTTP header has been received. This method must return quickly without blocking the thread how to go on. For example, this could look as follows:
`Static
, `File
, or, if computed, using `Reject_body
.process_header
call is simply the result of the
process_header
call of the other service provider.`File
. Otherwise, return `Accept_body
to continue with the
second stage. Note that even if no body is expected to arrive, one must
go through the second stage, and drop any unexpected body.The argument of this function is the Netcgi environment. The header is complete, including the request method. One cannot access the input and output channels at this stage of processing.
update_alist updl l
: Returns the alist with all elements of updl
and all elements of l
that are not member of updl
.