summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBert JW Regeer <bertjw@regeer.org>2015-04-11 12:17:43 -0400
committerBert JW Regeer <bertjw@regeer.org>2015-04-12 16:18:22 -0400
commit1cc3340fabb638407cbdc8d7b7b1c09a7eca8148 (patch)
tree6b6469f04c7ee24291a0c123958d0b0107ace0e7
parentb2d0b90f05577212a294678610a3094e37ff83a7 (diff)
downloadwebob-1cc3340fabb638407cbdc8d7b7b1c09a7eca8148.tar.gz
Request.POST should not replace Request.body_file
FakeCGIBody mangles anything that isn't actually form-encoded, such as JSON that isn't sent with the appropriate content type. We hereby remove the usage of FakeCGIBody and instead just make the body itself seekable.
-rw-r--r--tests/test_request.py4
-rw-r--r--webob/request.py11
2 files changed, 6 insertions, 9 deletions
diff --git a/tests/test_request.py b/tests/test_request.py
index 6637e61..caaafdd 100644
--- a/tests/test_request.py
+++ b/tests/test_request.py
@@ -524,8 +524,8 @@ class TestRequestCommon(unittest.TestCase):
r_1 = req.body
r_2 = req.POST
r_3 = req.body
- self.assertEqual(r_1, '{"password": "last centurion", "email": "rory@wiggy.net"}')
- self.assertEqual(r_3, '{"password": "last centurion", "email": "rory@wiggy.net"}')
+ self.assertEqual(r_1, b'{"password": "last centurion", "email": "rory@wiggy.net"}')
+ self.assertEqual(r_3, b'{"password": "last centurion", "email": "rory@wiggy.net"}')
def test_PUT_bad_content_type(self):
from webob.multidict import NoVars
diff --git a/webob/request.py b/webob/request.py
index 01c170f..8269ac5 100644
--- a/webob/request.py
+++ b/webob/request.py
@@ -785,8 +785,10 @@ class BaseRequest(object):
return NoVars('Not an HTML form submission (Content-Type: %s)'
% content_type)
self._check_charset()
- if self.is_body_seekable:
- self.body_file_raw.seek(0)
+
+ self.make_body_seekable()
+ self.body_file_raw.seek(0)
+
fs_environ = env.copy()
# FieldStorage assumes a missing CONTENT_LENGTH, but a
# default of 0 is better:
@@ -806,11 +808,6 @@ class BaseRequest(object):
keep_blank_values=True)
vars = MultiDict.from_fieldstorage(fs)
-
- #ctype = self.content_type or 'application/x-www-form-urlencoded'
- ctype = self._content_type_raw or 'application/x-www-form-urlencoded'
- f = FakeCGIBody(vars, ctype)
- self.body_file = io.BufferedReader(f)
env['webob._parsed_post_vars'] = (vars, self.body_file_raw)
return vars