[etwist] Fix an empty request content after a Twisted processing (closes #3546795).
authorDamien Garaud <damien.garaud@logilab.fr>
Fri, 14 Feb 2014 15:22:56 +0100
changeset 9533 fa4051e29fbe
parent 9532 99774ed8036e
child 9534 34d9de030564
[etwist] Fix an empty request content after a Twisted processing (closes #3546795). The content of a POST request could be empty when the Twisted server is used.
etwist/server.py
etwist/test/data/views.py
etwist/test/unittest_server.py
--- a/etwist/server.py	Thu Feb 13 16:50:55 2014 +0100
+++ b/etwist/server.py	Fri Feb 14 15:22:56 2014 +0100
@@ -238,6 +238,7 @@
         key, pdict = parse_header(ctype)
         if key == 'application/x-www-form-urlencoded':
             self.args.update(http.parse_qs(self.content.read(), 1))
+            self.content.seek(0)
         elif key == 'multipart/form-data':
             # defer this as it can be extremely time consumming
             # with big files
--- a/etwist/test/data/views.py	Thu Feb 13 16:50:55 2014 +0100
+++ b/etwist/test/data/views.py	Fri Feb 14 15:22:56 2014 +0100
@@ -22,7 +22,7 @@
 
 class PutView(View):
     __regid__ = 'put'
-    __select__ = match_http_method('PUT')
+    __select__ = match_http_method('PUT') | match_http_method('POST')
     binary = True
 
     def call(self):
--- a/etwist/test/unittest_server.py	Thu Feb 13 16:50:55 2014 +0100
+++ b/etwist/test/unittest_server.py	Fri Feb 14 15:22:56 2014 +0100
@@ -17,6 +17,7 @@
 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
 
 import os, os.path as osp, glob
+import urllib
 
 from cubicweb.devtools.testlib import CubicWebTC
 from cubicweb.devtools.httptest import CubicWebServerTC
@@ -57,9 +58,14 @@
 
 class ETwistHTTPTC(CubicWebServerTC):
     def test_put_content(self):
-        body = 'hop'
+        data = {'hip': 'hop'}
+        headers = {'Content-Type': 'application/x-www-form-urlencoded'}
+        body = urllib.urlencode(data)
         response = self.web_request('?vid=put', method='PUT', body=body)
         self.assertEqual(body, response.body)
+        response = self.web_request('?vid=put', method='POST', body=body,
+                                    headers=headers)
+        self.assertEqual(body, response.body)
 
 if __name__ == '__main__':
     from logilab.common.testlib import unittest_main