30 from StringIO import StringIO |
30 from StringIO import StringIO |
31 from urllib import quote |
31 from urllib import quote |
32 from urlparse import parse_qs |
32 from urlparse import parse_qs |
33 from warnings import warn |
33 from warnings import warn |
34 |
34 |
35 from cubicweb.multipart import copy_file, parse_form_data |
35 from cubicweb.multipart import ( |
|
36 copy_file, parse_form_data, MultipartError, parse_options_header) |
|
37 from cubicweb.web import RequestError |
36 from cubicweb.web.request import CubicWebRequestBase |
38 from cubicweb.web.request import CubicWebRequestBase |
37 from cubicweb.wsgi import pformat, normalize_header |
39 from cubicweb.wsgi import pformat, normalize_header |
38 |
40 |
39 |
41 |
40 class CubicWebWsgiRequest(CubicWebRequestBase): |
42 class CubicWebWsgiRequest(CubicWebRequestBase): |
146 def get_posted_data(self): |
148 def get_posted_data(self): |
147 # The WSGI spec says 'QUERY_STRING' may be absent. |
149 # The WSGI spec says 'QUERY_STRING' may be absent. |
148 post = parse_qs(self.environ.get('QUERY_STRING', '')) |
150 post = parse_qs(self.environ.get('QUERY_STRING', '')) |
149 files = None |
151 files = None |
150 if self.method == 'POST': |
152 if self.method == 'POST': |
151 forms, files = parse_form_data(self.environ, strict=True, |
153 content_type = self.environ.get('CONTENT_TYPE') |
152 mem_limit=self.vreg.config['max-post-length']) |
154 if not content_type: |
153 post.update(forms.dict) |
155 raise RequestError("Missing Content-Type") |
|
156 content_type, options = parse_options_header(content_type) |
|
157 if content_type in ( |
|
158 'multipart/form-data', |
|
159 'application/x-www-form-urlencoded', |
|
160 'application/x-url-encoded'): |
|
161 forms, files = parse_form_data( |
|
162 self.environ, strict=True, |
|
163 mem_limit=self.vreg.config['max-post-length']) |
|
164 post.update(forms.dict) |
154 self.content.seek(0, 0) |
165 self.content.seek(0, 0) |
155 return post, files |
166 return post, files |
156 |
167 |
157 def setup_params(self, params): |
168 def setup_params(self, params): |
158 # This is a copy of CubicWebRequestBase.setup_params, but without |
169 # This is a copy of CubicWebRequestBase.setup_params, but without |