The request handler is the layer which connects Apache with the underlying
application's request dispatcher (i.e. either Rails's Dispatcher
class or Rack). The request handler's job is to
process incoming HTTP requests using the currently loaded Ruby on Rails
application. HTTP requests are forwarded to the request handler by the web
server. HTTP responses generated by the RoR application are forwarded to
the web server, which, in turn, sends the response back to the HTTP client.
AbstractRequestHandler is an
abstract base class for easing the implementation of request handlers for
Rails and Rack.
Design decisions¶ ↑
Some design decisions are made because we want to decrease system
administrator maintenance overhead. These decisions are documented in this
section.
Owner pipes¶ ↑
Because only the web server communicates directly with a request handler,
we want the request handler to exit if the web server has also exited. This
is implemented by using a so-called _owner pipe_. The writable part of the
pipe will be passed to the web server* via a Unix socket, and the web
server will own that part of the pipe, while AbstractRequestHandler owns the
readable part of the pipe. AbstractRequestHandler will
continuously check whether the other side of the pipe has been closed. If
so, then it knows that the web server has exited, and so the request
handler will exit as well. This works even if the web server gets killed by
SIGKILL.
Incoming “HTTP requests” are not true HTTP requests, i.e. their binary
representation do not conform to RFC 2616. Instead, the request format is
based on CGI, and is similar to that of SCGI.
The format consists of 3 parts:
-
A 32-bit big-endian integer, containing the size of the transformed
headers.
-
The transformed HTTP headers.
-
The verbatim (untransformed) HTTP request body.
HTTP headers are transformed to a format that satisfies the following
grammar:
headers ::= header*
header ::= name NUL value NUL
name ::= notnull+
value ::= notnull+
notnull ::= "\x01" | "\x02" | "\x02" | ... | "\xFF"
NUL = "\x00"
The web server transforms the HTTP request to the aforementioned format,
and sends it to the request handler.