--- a/http.py Mon Feb 09 06:11:51 2009 +0200
+++ b/http.py Mon Feb 09 06:55:51 2009 +0200
@@ -29,6 +29,28 @@
# parse query args
self.arg_dict = cgi.parse_qs(self.arg_str, True)
+
+ # load post data?
+ if self.is_post() :
+ # content-type of post data
+ content_type = self.env.get('CONTENT_TYPE', 'application/x-www-form-urlencoded')
+
+ # valid content-type?
+ # XXX: how to handle errors?
+ assert any(content_type.startswith(x) for x in (
+ 'application/x-www-form-urlencoded',
+ 'multipart/form-data'
+ ))
+
+ # input stream
+ input = self.env['wsgi.input']
+
+ # use cgi.FieldStorage to parse this
+ self.post_data = cgi.FieldStorage(fp=input, environ=self.env, keep_blank_values=1)
+
+ else :
+ # no post data
+ self.post_data = None
@property
def site_host (self) :
@@ -116,6 +138,25 @@
"""
return cgi.parse_qsl(self.arg_str)
+
+ def is_post (self) :
+ """
+ Is this a POST request?
+ """
+
+ # just check REQUEST_METHOD
+ return (self.env['REQUEST_METHOD'].upper() == 'POST')
+
+ def get_post (self, name) :
+ """
+ Get the value of the given POST field
+ """
+
+ # sanity-check
+ assert self.post_data
+
+ # return the FieldStorage value
+ return self.post_data[name].value
class Response (object) :
"""