[Zope-Checkins] SVN: Zope/branches/blob-integration-test/lib/python/ZPublisher/ 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.

Chris McDonough chrism at plope.com
Mon Feb 27 19:29:15 EST 2006


Log message for revision 65554:
  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.
  
  

Changed:
  U   Zope/branches/blob-integration-test/lib/python/ZPublisher/HTTPRequest.py
  U   Zope/branches/blob-integration-test/lib/python/ZPublisher/tests/testHTTPRequest.py

-=-
Modified: Zope/branches/blob-integration-test/lib/python/ZPublisher/HTTPRequest.py
===================================================================
--- Zope/branches/blob-integration-test/lib/python/ZPublisher/HTTPRequest.py	2006-02-28 00:27:35 UTC (rev 65553)
+++ Zope/branches/blob-integration-test/lib/python/ZPublisher/HTTPRequest.py	2006-02-28 00:29:14 UTC (rev 65554)
@@ -375,6 +375,15 @@
         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
 

Modified: Zope/branches/blob-integration-test/lib/python/ZPublisher/tests/testHTTPRequest.py
===================================================================
--- Zope/branches/blob-integration-test/lib/python/ZPublisher/tests/testHTTPRequest.py	2006-02-28 00:27:35 UTC (rev 65553)
+++ Zope/branches/blob-integration-test/lib/python/ZPublisher/tests/testHTTPRequest.py	2006-02-28 00:29:14 UTC (rev 65554)
@@ -14,11 +14,11 @@
 
 
 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 @@
 
         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 @@
         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'),



More information about the Zope-Checkins mailing list