43 |
43 |
44 def __init__(self, environ, vreg): |
44 def __init__(self, environ, vreg): |
45 self.environ = environ |
45 self.environ = environ |
46 self.path = environ['PATH_INFO'] |
46 self.path = environ['PATH_INFO'] |
47 self.method = environ['REQUEST_METHOD'].upper() |
47 self.method = environ['REQUEST_METHOD'].upper() |
48 self.content = environ['wsgi.input'] |
48 try: |
|
49 length = int(environ['CONTENT_LENGTH']) |
|
50 except (KeyError, ValueError): |
|
51 length = 0 |
|
52 # wsgi.input is not seekable, so copy the request contents to a temporary file |
|
53 if length < 100000: |
|
54 self.content = StringIO() |
|
55 else: |
|
56 self.content = tempfile.TemporaryFile() |
|
57 safe_copyfileobj(environ['wsgi.input'], self.content, size=length) |
|
58 self.content.seek(0, 0) |
49 |
59 |
50 headers_in = dict((normalize_header(k[5:]), v) for k, v in self.environ.items() |
60 headers_in = dict((normalize_header(k[5:]), v) for k, v in self.environ.items() |
51 if k.startswith('HTTP_')) |
61 if k.startswith('HTTP_')) |
52 https = environ.get("HTTPS") in ('yes', 'on', '1') |
62 https = environ.get("HTTPS") in ('yes', 'on', '1') |
53 post, files = self.get_posted_data() |
63 post, files = self.get_posted_data() |
137 return post, files |
147 return post, files |
138 |
148 |
139 @property |
149 @property |
140 @cached |
150 @cached |
141 def raw_post_data(self): |
151 def raw_post_data(self): |
142 buf = StringIO() |
152 postdata = self.content.read() |
143 try: |
153 self.content.seek(0, 0) |
144 # CONTENT_LENGTH might be absent if POST doesn't have content at all (lighttpd) |
|
145 content_length = int(self.environ.get('CONTENT_LENGTH', 0)) |
|
146 except ValueError: # if CONTENT_LENGTH was empty string or not an integer |
|
147 content_length = 0 |
|
148 if content_length > 0: |
|
149 safe_copyfileobj(self.environ['wsgi.input'], buf, |
|
150 size=content_length) |
|
151 postdata = buf.getvalue() |
|
152 buf.close() |
|
153 return postdata |
154 return postdata |