Request » History » Version 3
Elmer de Looff, 2012-04-27 09:39
1 | 1 | Jan Klopper | h1. Request |
---|---|---|---|
2 | 1 | Jan Klopper | |
3 | 3 | Elmer de Looff | The @Request@ object is an abstraction of the incoming HTTP request. This allows one simple interface that is independent of the underlying server that µWeb runs on (either [[Standalone]] using BaseHTTPServer, or [[Apache]] mode on @mod_python@). |
4 | 1 | Jan Klopper | |
5 | 3 | Elmer de Looff | From PageMaker methods, the request object is accessible as the @self.req@ member. The request object contains all the information about the incoming request: query arguments, post data, cookies and environment data. It is also the place where you define outgoing cookies and |
6 | 1 | Jan Klopper | |
7 | 1 | Jan Klopper | * env |
8 | 1 | Jan Klopper | * headers |
9 | 1 | Jan Klopper | |
10 | 1 | Jan Klopper | h2. Post vars |
11 | 1 | Jan Klopper | |
12 | 1 | Jan Klopper | POST arguments can be found under: self.post and should be accessed by issueing a 'getfirst()', or 'getlist()' call for the desired key. |
13 | 1 | Jan Klopper | self.post.getfirst() allows for a second argument to set a default if the desired key isn't set by the browser |
14 | 1 | Jan Klopper | |
15 | 1 | Jan Klopper | <pre> |
16 | 1 | Jan Klopper | <code class="html"> |
17 | 1 | Jan Klopper | argA = self.post.getfirst('argA') |
18 | 1 | Jan Klopper | argB = self.post.getfirst('argB', 'empty') |
19 | 1 | Jan Klopper | |
20 | 1 | Jan Klopper | if 'argA' in self.post: |
21 | 1 | Jan Klopper | #pass, argA has been send by the browser |
22 | 1 | Jan Klopper | |
23 | 1 | Jan Klopper | </code> |
24 | 1 | Jan Klopper | </pre> |
25 | 1 | Jan Klopper | |
26 | 1 | Jan Klopper | h2. Get vars |
27 | 1 | Jan Klopper | |
28 | 1 | Jan Klopper | GET arguments can be found under: self.get, they work the same as POST vars. |
29 | 1 | Jan Klopper | |
30 | 1 | Jan Klopper | h2. Cookies |
31 | 2 | Elmer de Looff | |
32 | 1 | Jan Klopper | self.cookies contains the cookies send by the browser, as the interface to create them from the server. |
33 | 1 | Jan Klopper | |
34 | 1 | Jan Klopper | h3. Retrieving a cookie |
35 | 1 | Jan Klopper | You can fetch the content of cookie by accessig the self.cookie dict with the name of the desired cookie as its key. |
36 | 1 | Jan Klopper | The returned cookie object has a value member containing the actual value of the requested cookie. |
37 | 1 | Jan Klopper | <pre> |
38 | 1 | Jan Klopper | <code class="python"> |
39 | 1 | Jan Klopper | self.cookies['sample'].value |
40 | 1 | Jan Klopper | </code> |
41 | 1 | Jan Klopper | </pre> |
42 | 1 | Jan Klopper | |
43 | 1 | Jan Klopper | h2. ENV |
44 | 1 | Jan Klopper | |
45 | 1 | Jan Klopper | The env variable is a dictionary containing the following items; |
46 | 1 | Jan Klopper | * CONTENT_TYPE |
47 | 1 | Jan Klopper | * CONTENT_LENGTH |
48 | 1 | Jan Klopper | * HTTP_COOKIE |
49 | 1 | Jan Klopper | * HTTP_HOST |
50 | 1 | Jan Klopper | * HTTP_REFERER |
51 | 1 | Jan Klopper | * HTTP_USER_AGENT |
52 | 1 | Jan Klopper | * PATH_INFO |
53 | 1 | Jan Klopper | * QUERY_STRING |
54 | 1 | Jan Klopper | * REMOTE_ADDR |
55 | 1 | Jan Klopper | * REQUEST_METHOD |
56 | 1 | Jan Klopper | * UWEB_MODE 'STANDALONE' / 'MOD_PYTHON' |
57 | 1 | Jan Klopper | |
58 | 1 | Jan Klopper | h3. Extended env |
59 | 1 | Jan Klopper | 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. |
60 | 1 | Jan Klopper | |
61 | 1 | Jan Klopper | * AUTH_TYPE |
62 | 1 | Jan Klopper | * CONNECTION_ID |
63 | 1 | Jan Klopper | * DOCUMENT_ROOT |
64 | 1 | Jan Klopper | * RAW_REQUEST |
65 | 1 | Jan Klopper | * REMOTE_HOST |
66 | 1 | Jan Klopper | * REMOTE_USER |
67 | 1 | Jan Klopper | * SERVER_NAME |
68 | 1 | Jan Klopper | * SERVER_PORT |
69 | 1 | Jan Klopper | * SERVER_LOCAL_NAME |
70 | 1 | Jan Klopper | * SERVER_LOCAL_IP |
71 | 1 | Jan Klopper | * SERVER_PROTOCOL |
72 | 1 | Jan Klopper | |
73 | 2 | Elmer de Looff | And in case of a @mod_python@ setup you will also get: |
74 | 1 | Jan Klopper | * MODPYTHON_HANDLER |
75 | 1 | Jan Klopper | * MODPYTHON_INTERPRETER |
76 | 1 | Jan Klopper | * MODPYTHON_PHASE |