Commit 356b4f3b authored by Chris McDonough's avatar Chris McDonough

We don't need to do any real input processing if we are handling a PUT request...

We don't need to do any real input processing if we are handling a PUT request because in practice, the body is never mime-encoded.  This is an optimization especially because FieldStorage creates an additional tempfile if we allow it to parse the body, and PUT uploads can tend to be large.

In particular, this will be important for upload of large blobs.
parent fe7124a9
......@@ -375,6 +375,15 @@ class HTTPRequest(BaseRequest):
environ=self.environ
method=environ.get('REQUEST_METHOD','GET')
if method == 'PUT':
# we don't need to do any real input processing if we are handling
# a PUT request because in practice, the body is never
# mime-encoded. This is an optimization especially because
# FieldStorage creates an additional tempfile if we allow it to
# parse the body, and PUT uploads can tend to be large.
self._file = self.stdin
return
if method != 'GET': fp=self.stdin
else: fp=None
......
......@@ -14,11 +14,11 @@ class RecordTests( unittest.TestCase ):
class ProcessInputsTests(unittest.TestCase):
def _getHTTPRequest(self, env):
def _getHTTPRequest(self, env, stdin=None):
from ZPublisher.HTTPRequest import HTTPRequest
return HTTPRequest(None, env, None)
return HTTPRequest(stdin, env, None)
def _processInputs(self, inputs):
def _processInputs(self, inputs, extraenv=None, stdin=None):
# Have the inputs processed, and return a HTTPRequest object holding the
# result.
# inputs is expected to be a list of (key, value) tuples, no CGI
......@@ -32,7 +32,9 @@ class ProcessInputsTests(unittest.TestCase):
env = {'SERVER_NAME': 'testingharnas', 'SERVER_PORT': '80'}
env['QUERY_STRING'] = query_string
req = self._getHTTPRequest(env)
if extraenv is not None:
env.update(extraenv)
req = self._getHTTPRequest(env, stdin)
req.processInputs()
self._noFormValuesInOther(req)
return req
......@@ -154,6 +156,15 @@ class ProcessInputsTests(unittest.TestCase):
self._noTaintedValues(req)
self._onlyTaintedformHoldsTaintedStrings(req)
def testPUTShortcut(self):
# PUT requests are not fed through cgi.FieldStorage because
# their bodies are never (in practice, anyway) MIME-encoded, and
# we don't want FieldStorage to create a separate tempfile copy for
# large uploads.
stdin = []
req = self._processInputs((), {'REQUEST_METHOD':'PUT'}, stdin)
self.assert_(req._file is stdin)
def testUnicodeConversions(self):
inputs = (('ustring:ustring:utf8', 'test\xc2\xae'),
('utext:utext:utf8', 'test\xc2\xae\ntest\xc2\xae\n'),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment