Project

General

Profile

Request » History » Version 1

Version 1/23 - Next » - Current version
Jan Klopper, 2012-03-13 15:37


Request

The request object in µWeb makes sure each request from the browser, independent of coming from a mod_python instance or the standalone server looks the same.

You can reach the request object inside a pagemaker by using the self.req variable.
It is presented as an object with the following members:

  • env
  • headers

Post vars

POST arguments can be found under: self.post and should be accessed by issueing a 'getfirst()', or 'getlist()' call for the desired key.
self.post.getfirst() allows for a second argument to set a default if the desired key isn't set by the browser

argA = self.post.getfirst('argA')
argB = self.post.getfirst('argB', 'empty')

if 'argA' in self.post:
  #pass, argA has been send by the browser


Get vars

GET arguments can be found under: self.get, they work the same as POST vars.

Cookies
  1. TODO
    self.cookies contains the cookies send by the browser, as the interface to create them from the server.

Retrieving a cookie
You can fetch the content of cookie by accessig the self.cookie dict with the name of the desired cookie as its key.
The returned cookie object has a value member containing the actual value of the requested cookie.
self.cookies['sample'].value

ENV

The env variable is a dictionary containing the following items;
  • CONTENT_TYPE
  • CONTENT_LENGTH
  • HTTP_COOKIE
  • HTTP_HOST
  • HTTP_REFERER
  • HTTP_USER_AGENT
  • PATH_INFO
  • QUERY_STRING
  • REMOTE_ADDR
  • REQUEST_METHOD
  • UWEB_MODE 'STANDALONE' / 'MOD_PYTHON'

Extended env
If more detail is required about the environment, you can issue a call to the self.req.ExtendedEnvironment() method, which will inject more details into the env var. This is a much slower operation than the normal env call, so that's why its tucked away in a separate method.

  • AUTH_TYPE
  • CONNECTION_ID
  • DOCUMENT_ROOT
  • RAW_REQUEST
  • REMOTE_HOST
  • REMOTE_USER
  • SERVER_NAME
  • SERVER_PORT
  • SERVER_LOCAL_NAME
  • SERVER_LOCAL_IP
  • SERVER_PROTOCOL
And in case of a mod_python setup you will also get:
  • MODPYTHON_HANDLER
  • MODPYTHON_INTERPRETER
  • MODPYTHON_PHASE

Persistent storage between requests

µWeb allows you to store objects in persistent storage if in standalone to avoid recreating them every single request. for this purpose the self.persistent member exists from which you can read with the 'Get()' method and write to using the 'Set()' method.

self.persistent.Set() takes two arguments, a key by which to retrieve the value later and the value itself (which can be any python object)