Cerise handles HTTP requests and responses via a custom HTTP 1.1 server. Another server such as Apache can be used as a front-end with appropriate configuration. However, a cerise application sees requests as coming from the cerise HTTP server and needs to know how the request and response are handled.
HTTP requests are encapsulated in a Cerise::HTTP::Request
object.
The client ip address and source port are available through client_ip and client_port accessors.
The Request class provides access to the request method,
path, and version via accessors of the same name.
:OPTIONS, :GET, :HEAD, :POST, :PUT, :DELETE, :TRACE
The HTTP headers are available via a call to headers which
returns a Hash of name-value pairs. Header names are converted
to lowercase, so accessing the 'Connection' header should be done as
request.headers['connection'] rather than
request.headers['Connection']. This avoids a lowercase
conversion on each request to a particular header.
When multiple headers with the same name are received, they are condensed into a single header with the values separated by commas.
If a query is passed via the request URI or a POST body, it is available
in query which is a hash of name-value pairs. The value is stored
as a String, or an Array if multiple values are passed, unless
the content is MIME encoded. In the case of MIME encoding the value may
be a simple String or a Cerise::Mime::MimePart.
The content, if any, of a request is available in body. The
object contained in body can be of several types:
The HTTP response is encapsulated in a Cerise::HTTP::Response
object.
If necessary, the HTTP response code may be set via code. This
takes either a Cerise::HTTP::StatusCode or a
Cerise::HTTP::ErrorCode
Response headers can be accessed by calling headers which returns a Hash of key-value pairs as in the Request.
The body of the response is stored in body and may be of
any type that supports a size method to get
the content length, and a http_write(io) method to write the
content to the response IO stream. These methods already exist or are
provided for the following types:
Cookies are supported in the request and response via
the accessor cookies which returns an Array of
Cerise::HTTP::Cookie objects.