[Checkins] SVN: zope.publisher/trunk/ Bug fixed:
Jim Fulton
jim at zope.com
Sun Mar 23 15:01:27 EDT 2008
Log message for revision 84885:
Bug fixed:
When posting non-form (and non-multipart) data, the request body was
consumed and discarded. This makes it impossible to deal with other
post types, like xml-rpc or json without resorting to overly complex
"request factory" contortions.
Changed:
U zope.publisher/trunk/CHANGES.txt
U zope.publisher/trunk/src/zope/publisher/browser.py
U zope.publisher/trunk/src/zope/publisher/tests/test_browserrequest.py
-=-
Modified: zope.publisher/trunk/CHANGES.txt
===================================================================
--- zope.publisher/trunk/CHANGES.txt 2008-03-23 17:10:19 UTC (rev 84884)
+++ zope.publisher/trunk/CHANGES.txt 2008-03-23 19:01:26 UTC (rev 84885)
@@ -2,6 +2,16 @@
CHANGES
=======
+3.5.1 (2008-03-23)
+------------------
+
+Bugs fixed:
+
+When posting non-form (and non-multipart) data, the request body was
+consumed and discarded. This makes it impossible to deal with other
+post types, like xml-rpc or json without resorting to overly complex
+"request factory" contortions.
+
3.5.0 (2008-03-02)
------------------
Modified: zope.publisher/trunk/src/zope/publisher/browser.py
===================================================================
--- zope.publisher/trunk/src/zope/publisher/browser.py 2008-03-23 17:10:19 UTC (rev 84884)
+++ zope.publisher/trunk/src/zope/publisher/browser.py 2008-03-23 19:01:26 UTC (rev 84885)
@@ -210,6 +210,7 @@
+ ", ".join(["%s: %s" % (key, repr(value))
for key, value in items]) + "}")
+_get_or_head = 'GET', 'HEAD'
class BrowserRequest(HTTPRequest):
implements(IBrowserRequest, IBrowserApplicationRequest)
@@ -252,9 +253,20 @@
def processInputs(self):
'See IPublisherRequest'
- if self.method != 'GET':
+ if self.method not in _get_or_head:
# Process self.form if not a GET request.
fp = self._body_instream
+ if self.method == 'POST':
+ content_type = self._environ.get('CONTENT_TYPE')
+ if content_type and not (
+ content_type == 'application/x-www-form-urlencoded'
+ or
+ content_type.startswith('multipart/')
+ ):
+ # for non-multi and non-form content types, FieldStorage
+ # consumes the body and we have no good place to put it.
+ # So we just won't call FieldStorage. :)
+ return
else:
fp = None
Modified: zope.publisher/trunk/src/zope/publisher/tests/test_browserrequest.py
===================================================================
--- zope.publisher/trunk/src/zope/publisher/tests/test_browserrequest.py 2008-03-23 17:10:19 UTC (rev 84884)
+++ zope.publisher/trunk/src/zope/publisher/tests/test_browserrequest.py 2008-03-23 19:01:26 UTC (rev 84885)
@@ -480,6 +480,15 @@
self.assertEqual(request.form, {u'HTTP_REFERER': u'peter'})
+ def test_post_body_not_consumed_unnecessarily(self):
+ request = self._createRequest(
+ dict(REQUEST_METHOD='POST',
+ CONTENT_TYPE='application/x-foo',
+ ),
+ 'test body')
+ request.processInputs()
+ self.assertEqual(request.bodyStream.read(), 'test body')
+
class TestBrowserPublication(TestPublication):
implements(IBrowserPublication)
More information about the Checkins
mailing list