James Gardner: Home > Work > Code > HTTPKit > 0.1.1 > Manual

HTTPKit v0.1.1 documentation

Manual

HTTPKit is a set of services for handling the features of the HTTP protocol which are useful to simple web applications. It existis in two logical parts:

  • Helpers
  • Services

The helpers are simple functions you can use in any application to manipulate HTTP data. The services use these helpers to provide the http key for the Flows framework and may not be as useful unless you are using flows.

At the moment the helpers are very simple and provide only the following functions:

Set (add) a cookie for the response

Let’s concentrate on the services.

HTTPService

The heart of the HTTPKit services is HTTPService. This service sets up the http key on the flow object to provide HTTP access to Flows applications.

The API of the HTTPService looks like this:

Request API:

flow.http.environ
The underlying environment containing all the HTTP headers as well as environment data. Depending on how the application is deployed this could be the WSGI environment and contain the WSGI keys too.

Response API:

flow.http.response.status
A string representing the HTTP response status. eg "200 OK" or "404 Not Found"
flow.http.response.headers
A list of WSGI http header tuple pairs. eg [('Content-Type', 'text/html')].
flow.http.response.body
Either a list of Unicode strings or an iterable which when iterated over returns a series of bytes representing the response.

HTTPInputService

This service reads the wsgi.input key from flow.http.environ and parses it to a cgi.FieldStorage object. If there is no POST data then flow.http.input will be None, otherwise you can access the data like this:

flow.http.input['name'].getfirst()
flow.http.input['name'].getlist()

The wsgi.input value is replaced with a StringIO.StringIO object so that any code dispatched with the WSGI service can parse the data again.

HTTPQueryService

This service reads the QUERY_STRING key from flow.http.environ and parses it to a cgi.FieldStorage object. If there is no QUERY_STRING then flow.http.query will be None, otherwise you can access the data like this:

flow.http.query['name'].getfirst()
flow.http.query['name'].getlist()
James Gardner: Home > Work > Code > HTTPKit > 0.1.1 > Manual