4Suite™ API Documentation

# ► Module Ft.Server.Server.Http.BaseRequestHandler

Basic functionality common to all HTTP requests and responses
Copyright 2005 Fourthought, Inc. (USA).
Detailed license and copyright information: http://4suite.org/COPYRIGHT
Project home, documentation, distributions: http://4suite.org/

Classes: BaseRequestHandler

## Classes

class BaseRequestHandler(Ft.Server.Server.RequestHandler.RequestHandler)
This is the base class for all HTTP requests. It encapsulates the request read stream, the response write stream, the data from the request, and the data for the response. It also provides the functions to parse the and store the components of the request, determine the real path (in the repo) for the requested path, start handling the request including catching any exceptions, write out a response, and log the request and response.
Requires in its constructor a HttpConnection instance and
a ServerConfig instance.
Instance variables:
- connection: a HttpConnection instance
- server: the ServerConfig instance passed in the constructor -- used for
logging, document root, authentication, etc.
- rfile: request read stream
- wfile: response write stream
- request: the original Request-Line from the request
[RFC 2616 sect. 5.1]
- method: the Method for this request (like 'GET', 'POST', etc.)
[RFC 2616 sect. 5.1.1]
- unparsed_uri: the original Request-URI (typically URL-encoded)
[RFC 2616 sect. 5.1.2]
- unparsed_path: the path portion of the Request-URI
(assumes URI consists of an abs_path [RFC 2616 sect. 5.1.2]
and, because urllib is buggy, that the path stops at the first
';' or '?')
- unparsed_params: because urllib is buggy, the part of path
component of the Request-URI after the first ';'. This is a param
[RFC 2396 sect. 3.3]
- unparsed_args: the query component of the Request-URI
[RFC 2396 sect. 3.4]
- protocol: the protocol string as sent by the client, or 'HTTP/0.9'
- version: a float representing the version portion of the protocol
- headers_in: dictionary-like object of request headers
- path: the URL-decoded form of the unparsed_uri_path
- filename: the real path to the requested resource in the repo
- args: dictionary of unparsed_uri_args as returned by cgi.parse_qs()
- auth_type: authorization type from Authorization header of request
- user: username decoded from Authorization header of request
- password: password decoded from Authorization header of request
- body: request body as a string (bytes)
- headers_out: dictionary-like object of response headers

### Methods

__init__(self, connection)
authChecker(self, mandatory=False)
do_OPTIONS(self)
list the capabilities of this handler
generateRepoPath(self)
Attempts to convert the request URI to a repo path string and ftss URI, and stores those values.
Raises a ValueError exception if the conversion failed.
getMimeHeaders(self)
getRemoteHostname(self)
Return the client address, formatted for logging.
First the hostname returned by gethostbyaddr() is checked, then
possibly existing aliases. In case no FQDN is available, hostname
is returned.
getRepository(self, sendError=True)
getRequestArgs(self)
getRequestBody(self)
handle(self)
joinQueryArgs(self, args1, args2)
Join two query argument dicts.
Given two query string argument dictionaries from cgi.parse_qs(),
return a new dictionary of the combined arguments, appending the
values from args2 to the values for args1 for each duplicate key.
localDateTimeString(self)
Return the request time formatted for logging.
logTransaction(self)
parseUri(self, uri)
Parse the Request-URI, storing its components (path, query, etc.) in the instance (self.unparsed_path, self.path, etc.)
processRequest(self)
Handle a single HTTP request.
processResponse(self)
readRequest(self)
readRequestLine(self)
Parse the Request-Line of an HTTP request coming in via the rfile stream. The Request-Line is the first line of the request. (It should look like "GET /foo HTTP/1.1").
If the request line is in some way malformed, an error repsonse
is written directly to the wfile stream and false is returned,
otherwise true indicates success.
Progress and errors are logged to server.errorLog.
rfcDateTimeString(self)
Return the request time formatted for a message header.
send_error(self, code, **keywords)
Send and log an error reply.
Arguments are the error code, and a detailed message.
The detailed message defaults to the short entry matching the
response code.
This sends an error response (so it must be called before any
output has been generated), logs the error, and finally sends
a piece of HTML explaining the error to the user.
unhandledException(self, function)

### Fields

monthname = ['', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
sys_version = 'Python/2.4.4'
weekdayname = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']