Request » History » Version 2
Elmer de Looff, 2012-04-23 17:26
1 | 1 | Jan Klopper | h1. Request |
---|---|---|---|
2 | 1 | Jan Klopper | |
3 | 1 | Jan Klopper | 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. |
4 | 1 | Jan Klopper | |
5 | 1 | Jan Klopper | You can reach the request object inside a [[pagemaker]] by using the self.req variable. |
6 | 1 | Jan Klopper | It is presented as an object with the following members: |
7 | 1 | Jan Klopper | |
8 | 1 | Jan Klopper | * env |
9 | 1 | Jan Klopper | * headers |
10 | 1 | Jan Klopper | |
11 | 1 | Jan Klopper | h2. Post vars |
12 | 1 | Jan Klopper | |
13 | 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. |
14 | 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 |
15 | 1 | Jan Klopper | |
16 | 1 | Jan Klopper | <pre> |
17 | 1 | Jan Klopper | <code class="html"> |
18 | 1 | Jan Klopper | argA = self.post.getfirst('argA') |
19 | 1 | Jan Klopper | argB = self.post.getfirst('argB', 'empty') |
20 | 1 | Jan Klopper | |
21 | 1 | Jan Klopper | if 'argA' in self.post: |
22 | 1 | Jan Klopper | #pass, argA has been send by the browser |
23 | 1 | Jan Klopper | |
24 | 1 | Jan Klopper | </code> |
25 | 1 | Jan Klopper | </pre> |
26 | 1 | Jan Klopper | |
27 | 1 | Jan Klopper | h2. Get vars |
28 | 1 | Jan Klopper | |
29 | 1 | Jan Klopper | GET arguments can be found under: self.get, they work the same as POST vars. |
30 | 1 | Jan Klopper | |
31 | 1 | Jan Klopper | h2. Cookies |
32 | 2 | Elmer de Looff | |
33 | 1 | Jan Klopper | self.cookies contains the cookies send by the browser, as the interface to create them from the server. |
34 | 1 | Jan Klopper | |
35 | 1 | Jan Klopper | h3. Retrieving a cookie |
36 | 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. |
37 | 1 | Jan Klopper | The returned cookie object has a value member containing the actual value of the requested cookie. |
38 | 1 | Jan Klopper | <pre> |
39 | 1 | Jan Klopper | <code class="python"> |
40 | 1 | Jan Klopper | self.cookies['sample'].value |
41 | 1 | Jan Klopper | </code> |
42 | 1 | Jan Klopper | </pre> |
43 | 1 | Jan Klopper | |
44 | 1 | Jan Klopper | h2. ENV |
45 | 1 | Jan Klopper | |
46 | 1 | Jan Klopper | The env variable is a dictionary containing the following items; |
47 | 1 | Jan Klopper | * CONTENT_TYPE |
48 | 1 | Jan Klopper | * CONTENT_LENGTH |
49 | 1 | Jan Klopper | * HTTP_COOKIE |
50 | 1 | Jan Klopper | * HTTP_HOST |
51 | 1 | Jan Klopper | * HTTP_REFERER |
52 | 1 | Jan Klopper | * HTTP_USER_AGENT |
53 | 1 | Jan Klopper | * PATH_INFO |
54 | 1 | Jan Klopper | * QUERY_STRING |
55 | 1 | Jan Klopper | * REMOTE_ADDR |
56 | 1 | Jan Klopper | * REQUEST_METHOD |
57 | 1 | Jan Klopper | * UWEB_MODE 'STANDALONE' / 'MOD_PYTHON' |
58 | 1 | Jan Klopper | |
59 | 1 | Jan Klopper | h3. Extended env |
60 | 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. |
61 | 1 | Jan Klopper | |
62 | 1 | Jan Klopper | * AUTH_TYPE |
63 | 1 | Jan Klopper | * CONNECTION_ID |
64 | 1 | Jan Klopper | * DOCUMENT_ROOT |
65 | 1 | Jan Klopper | * RAW_REQUEST |
66 | 1 | Jan Klopper | * REMOTE_HOST |
67 | 1 | Jan Klopper | * REMOTE_USER |
68 | 1 | Jan Klopper | * SERVER_NAME |
69 | 1 | Jan Klopper | * SERVER_PORT |
70 | 1 | Jan Klopper | * SERVER_LOCAL_NAME |
71 | 1 | Jan Klopper | * SERVER_LOCAL_IP |
72 | 1 | Jan Klopper | * SERVER_PROTOCOL |
73 | 1 | Jan Klopper | |
74 | 2 | Elmer de Looff | And in case of a @mod_python@ setup you will also get: |
75 | 1 | Jan Klopper | * MODPYTHON_HANDLER |
76 | 1 | Jan Klopper | * MODPYTHON_INTERPRETER |
77 | 1 | Jan Klopper | * MODPYTHON_PHASE |