7.11 Request Classes

#
7.11 Request Classes

The choice of `Request` class determines how you wish to deploy your application. Albatross supplies a number of pre-built Request implementations suited to various deployment methods. These include:

Deployment Method | Request Module
--- | ---
CGI | `albatross.cgiapp`
mod_python | `albatross.apacheapp`
FastCGI_python | `albatross.fcgiapp`
Stand-alone Python HTTP server | `albatross.httpdapp`

You can also develop your own `Request` class to deploy an Albatross application in other ways.

All `Request` classes implement the same interface. Much of this interface can be supplied by the `RequestBase` mixin.

`has_field`( | name)

  Returns `TRUE` if the field identified by the name argument is present in the request.

`field_value`( | name)

  Return the value of the field identified by the name argument.

`field_file`( | name)

  Returns an object that contains the value of a file input field.

`field_names`( | )

  Return a list of all all fields names in the request.

`get_uri`( | )

  Return the URL which the browser used to perform the request.

`get_servername`( | )

  Return the name of the server (Apache ServerName setting).

`get_header`( | name)

  Return the value of the HTTP header identified in the name argument.

`write_header`( | name, value)

  Add a header named name with the value value to the response. This method should not be called once you have started sending content to the browser.

`end_headers`( | )

  Signal to the Request object that header generation has finished and that you are ready to start sending content.

`redirect`( | loc)

  Send a `"301 Moved Permanently"` response back to the browser.

`write_content`( | data)

  Send data as part of the request response.

`set_status`( | status)

  Sets the HTTP status code of the response. Defaults to 200. For deployment methods based on the cgiapp module, this value is used to derive the `Status:` header. The apacheapp module uses it to set the `status` member of the mod_python `request` object.

`status`( | num)

  Return the saved value for the HTTP status code.

`return_code`( | )

  Returns a value which should be returned from the `Application` class `run()` method. For most deployment methods, this is `None`, however the `mod_python` requires that `mod_python.apache.OK` be returned if application emits any content. Your `mod_python` application should include code such as this:

      from albatross.apacheapp import Request
        :
        :
      def handler(req):
          return app.run(Request(req))