# wsgiAdaptor API

API for a simple WSGI web framework

## wsgiAdaptor

This class provides a basic web development framework that should work with any WSGI implementation.

### wsgiAdaptor (applicationObject, cookieKey, sessionClient)

The wsgiAdaptor object provides a basic web development environment within an WSGI server implementation.

- applicationObject - An object that provides a method `requestHandler (request)`. The requestHandler method must be multi-thread safe and return no value. The requestHandler is passed a Request object which contains details of the request, and provides methods to return content to the client.
- cookieKey - A secret key that is used to sign all outgoing cookies. This is used to detect when a client has modified or created a cookie in order to protect against session high-jacking.
- sessionClient - A session client object that provides the ability to save and load session data.

### wsgiHook (environment, start_response)

The method that the WSGI implementation should call.

## Request

An instance of this class is passed to the application's `requsetHandler` method for every request made of the application. If no "sendX" method is called before the handler returns then an Internal Server Error is sent to the client. The sendX methods can be called multiple times with only the last method called taking effect.

### getFormFields()

Returns a FieldStorage instance containing the GET or POST variables (see the Python standard libraries CGI module for more information).

### getSession()

Returns the session associated with this client. The session is a Mapping type (e.g. dictionary). Values added to the session will automatically be saved into the session. Be aware that as the size of the session increases the time taken to load and save the session will grow.

### getUsername()

The username of the authenticated user, or None if the user provided no username.

### getPassword()

The password used by the user to authenticate, None if no authentication is provided.

### getErrorStream()

Returns the stream that applications errors should be written to.

### getRelativePath()

Return the relative path (still URL escaped) that was passed to the application.

### getURLPrefix()

Returns the part of the URL up to the parameters (e.g http://server.com/scriptName.py).

### sendContent (contentValue, contentType = "text/plain")

Set the content to be sent to the client once the application returns. If the content is not plain text then the contentType should be specified as the second parameter.

### sendUnauthorisedBasic (realm)

Prompt the user for a username/password for the given realm.

### sendSeeOtherRedirect (newDestination)

Send a 303 HTTP redirect to the newDestination.

### sendResponse (responseStr, contentValue, contentType = "text/plain")

Set the response and content to be sent to the client once the application returns. The responseStr should be the HTTP response string, e.g. "500 Internal Error".

### sendFileForPath (path, rootDir = None)

Sets the content and contentType to be sent to the client based on the contents of a file for the given path. The path should be URL escaped. rootDir is the directory that the path is relative too, taking the current working directory if none is provided.

If the path reaches outside of the rootDir (e.g. a path of '../../etc/passwd') then an IOError is thrown. No other security checking is performed.