7.11 Request Classes
Description: Request Classes
Keywords: albatross

#
7.11 Request Classes

The choice of `Request` class determines how you wish to deploy your application. Albatross currently supplies two classes; `cgiapp.Request` for CGI deployment and `apacheapp.Request` for deployment using `mod_python`.

By placing all deployment dependencies in a `Request` class you are able to change deployment method with only minimal changes to your application mainline code. This is useful for development as a CGI application and final deployment inside Apache.

In theory you could develop your own `Request` class to deploy an Albatross application using the Medusa web server.

Future versions of Albatross will provide a `Request` class which for performing unit tests on your application.

All `Request` classes implement the same interface.

`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)

  Set the header named in the name argument to the value argument. Once you have started sending content to the browser the method will not do anything.

`end_headers`( | )

  Send all accumulated headers and start sending content. This method will be automatically called when you start sending content to the browser via `write_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 status that will be returned from the `Application` class `run()` method.

`status`( | num)

  Return a value for the HTTP status code in the num argument which is suitable for returning as the result of the application `run()` method.

  For example, the `mod_python` deployment typically uses this method in a roundabout way like this:

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