diff --git a/tests/test_request.py b/tests/test_request.py index 6910acc4..ecc47694 100644 --- a/tests/test_request.py +++ b/tests/test_request.py @@ -212,7 +212,7 @@ def test_copy(): assert req.body_file is old_body_file class UnseekableInputWithSeek(UnseekableInput): - def seek(self, pos): + def seek(self, pos, rel=0): raise IOError("Invalid seek!") def test_broken_seek(): diff --git a/webob/request.py b/webob/request.py index 25a3d14e..76c577ae 100644 --- a/webob/request.py +++ b/webob/request.py @@ -429,8 +429,9 @@ def _body__get(self): clen = self.content_length if clen is None: clen = -1 - r = self.body_file.read(clen) - self.body_file.seek(0) + f = self.environ['wsgi.input'] + r = f.read(clen) + f.seek(0) return r def _body__set(self, value): @@ -682,7 +683,7 @@ def _copy_body_tempfile(self): assert isinstance(length, int) if not tempfile_limit or length <= tempfile_limit: return False - fileobj = tempfile.TemporaryFile() + fileobj = self.make_tempfile() input = self.body_file while length: data = input.read(min(length, 65536)) @@ -692,6 +693,12 @@ def _copy_body_tempfile(self): self.environ['wsgi.input'] = fileobj return True + def make_tempfile(self): + """ + Create a tempfile to store big request body + """ + return tempfile.TemporaryFile() + def remove_conditional_headers(self, remove_encoding=True, remove_range=True, remove_match=True, remove_modified=True):