Log message for revision 65541:
  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/trunk/lib/python/ZPublisher/HTTPRequest.py
  U   Zope/trunk/lib/python/ZPublisher/tests/testHTTPRequest.py

-=-
Modified: Zope/trunk/lib/python/ZPublisher/HTTPRequest.py
===================================================================
--- Zope/trunk/lib/python/ZPublisher/HTTPRequest.py     2006-02-27 22:21:54 UTC 
(rev 65540)
+++ Zope/trunk/lib/python/ZPublisher/HTTPRequest.py     2006-02-27 22:27:29 UTC 
(rev 65541)
@@ -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/trunk/lib/python/ZPublisher/tests/testHTTPRequest.py
===================================================================
--- Zope/trunk/lib/python/ZPublisher/tests/testHTTPRequest.py   2006-02-27 
22:21:54 UTC (rev 65540)
+++ Zope/trunk/lib/python/ZPublisher/tests/testHTTPRequest.py   2006-02-27 
22:27:29 UTC (rev 65541)
@@ -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'),

_______________________________________________
Zope-Checkins maillist  -  Zope-Checkins@zope.org
http://mail.zope.org/mailman/listinfo/zope-checkins

Reply via email to