# HG changeset patch # User Damien Garaud # Date 1392387776 -3600 # Node ID fa4051e29fbe5700ec4968fffa907c2ae079df08 # Parent 99774ed8036e7b8b7ec376dd2c68bb36a432c368 [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. diff -r 99774ed8036e -r fa4051e29fbe etwist/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 diff -r 99774ed8036e -r fa4051e29fbe etwist/test/data/views.py --- 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): diff -r 99774ed8036e -r fa4051e29fbe etwist/test/unittest_server.py --- 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 . 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