From: Steve Baker Date: Thu, 20 Jun 2013 02:47:01 +0000 (+1200) Subject: Revert "check content type in JSONRequestDeserializer" X-Git-Tag: 2014.1~455 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=e0db33b515b4ca59d09ce9a01a87a855127e9b79;p=openstack-build%2Fheat-build.git Revert "check content type in JSONRequestDeserializer" For details of the regression this caused see bug: #1187882 This reverts commit 2f35c942e34b6c6538a2ae2da3d01b690af3a47f. Change-Id: Ib739d271f5caf0e8ce26c3b27a3436a20e9e311d --- diff --git a/heat/common/wsgi.py b/heat/common/wsgi.py index cc5b624d..2f0ecbcb 100644 --- a/heat/common/wsgi.py +++ b/heat/common/wsgi.py @@ -427,14 +427,6 @@ class Request(webob.Request): return content_type -def is_json_content_type(request): - content_type = request.params.get("ContentType") or request.content_type - if content_type in ('JSON', 'application/json')\ - and request.body.startswith('{'): - return True - return False - - class JSONRequestDeserializer(object): def has_body(self, request): """ @@ -442,7 +434,9 @@ class JSONRequestDeserializer(object): :param request: Webob.Request object """ - if request.content_length > 0 and is_json_content_type(request): + if 'transfer-encoding' in request.headers: + return True + elif request.content_length > 0: return True return False diff --git a/heat/tests/test_wsgi.py b/heat/tests/test_wsgi.py index 9cfe4b15..e2640c61 100644 --- a/heat/tests/test_wsgi.py +++ b/heat/tests/test_wsgi.py @@ -209,50 +209,11 @@ class JSONRequestDeserializerTest(HeatTestCase): request.headers['Content-Length'] = 0 self.assertFalse(wsgi.JSONRequestDeserializer().has_body(request)) - def test_has_body_has_content_length_no_content_type(self): + def test_has_body_has_content_length(self): request = wsgi.Request.blank('/') request.method = 'POST' request.body = 'asdf' self.assertTrue('Content-Length' in request.headers) - self.assertFalse(wsgi.JSONRequestDeserializer().has_body(request)) - - def test_has_body_has_content_type_malformed(self): - request = wsgi.Request.blank('/') - request.method = 'POST' - request.body = 'asdf' - self.assertTrue('Content-Length' in request.headers) - request.headers['Content-Type'] = 'application/json' - self.assertFalse(wsgi.JSONRequestDeserializer().has_body(request)) - - def test_has_body_has_content_type(self): - request = wsgi.Request.blank('/') - request.method = 'POST' - request.body = '{"key": "value"}' - self.assertTrue('Content-Length' in request.headers) - request.headers['Content-Type'] = 'application/json' - self.assertTrue(wsgi.JSONRequestDeserializer().has_body(request)) - - def test_has_body_has_wrong_content_type(self): - request = wsgi.Request.blank('/') - request.method = 'POST' - request.body = '{"key": "value"}' - self.assertTrue('Content-Length' in request.headers) - request.headers['Content-Type'] = 'application/xml' - self.assertFalse(wsgi.JSONRequestDeserializer().has_body(request)) - - def test_has_body_has_aws_content_type_only(self): - request = wsgi.Request.blank('/?ContentType=JSON') - request.method = 'GET' - request.body = '{"key": "value"}' - self.assertTrue('Content-Length' in request.headers) - self.assertTrue(wsgi.JSONRequestDeserializer().has_body(request)) - - def test_has_body_respect_aws_content_type(self): - request = wsgi.Request.blank('/?ContentType=JSON') - request.method = 'GET' - request.body = '{"key": "value"}' - self.assertTrue('Content-Length' in request.headers) - request.headers['Content-Type'] = 'application/xml' self.assertTrue(wsgi.JSONRequestDeserializer().has_body(request)) def test_no_body_no_content_length(self): @@ -280,7 +241,14 @@ class JSONRequestDeserializerTest(HeatTestCase): request = wsgi.Request.blank('/') request.method = 'POST' request.body = '{"key": "value"}' - request.headers['Content-Type'] = 'application/json' actual = wsgi.JSONRequestDeserializer().default(request) expected = {"body": {"key": "value"}} self.assertEqual(actual, expected) + + def test_has_body_has_transfer_encoding(self): + request = wsgi.Request.blank('/') + request.method = 'POST' + request.body = 'fake_body' + request.headers['transfer-encoding'] = 0 + self.assertTrue('transfer-encoding' in request.headers) + self.assertTrue(wsgi.JSONRequestDeserializer().has_body(request))