summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Waldon <brian.waldon@rackspace.com>2011-07-08 17:40:56 -0400
committerBrian Waldon <brian.waldon@rackspace.com>2011-07-08 17:40:56 -0400
commitb5ca0d793826ac10ee41be84f18d64b09113aa80 (patch)
tree4eef130b2d023048fe31a850f0cdd6609c93e9b3
parentfe8da67779dbb03654b1cce90eeafdb323507673 (diff)
downloadnova-b5ca0d793826ac10ee41be84f18d64b09113aa80.tar.gz
nova-b5ca0d793826ac10ee41be84f18d64b09113aa80.tar.xz
nova-b5ca0d793826ac10ee41be84f18d64b09113aa80.zip
refactor
-rw-r--r--nova/api/openstack/wsgi.py25
-rw-r--r--nova/tests/api/openstack/test_wsgi.py3
2 files changed, 16 insertions, 12 deletions
diff --git a/nova/api/openstack/wsgi.py b/nova/api/openstack/wsgi.py
index bd91aed60..7a8376722 100644
--- a/nova/api/openstack/wsgi.py
+++ b/nova/api/openstack/wsgi.py
@@ -52,9 +52,9 @@ class Request(webob.Request):
content_type = self.content_type
if content_type not in allowed_types:
- return None
- else:
- return content_type
+ raise exception.InvalidContentType(content_type=content_type)
+
+ return content_type
class TextDeserializer(object):
@@ -171,19 +171,22 @@ class RequestDeserializer(object):
def deserialize_body(self, request, action):
try:
content_type = request.get_content_type()
+ except exception.InvalidContentType:
+ LOG.debug(_("Unrecognized Content-Type provided in request"))
+ return {}
- if content_type is None:
- LOG.debug(_("No Content-Type provided in request"))
- return {}
+ if content_type is None:
+ LOG.debug(_("No Content-Type provided in request"))
+ return {}
- if not len(request.body) > 0:
- LOG.debug(_("Empty body provided in request"))
- return {}
+ if not len(request.body) > 0:
+ LOG.debug(_("Empty body provided in request"))
+ return {}
+ try:
deserializer = self.get_body_deserializer(content_type)
-
except exception.InvalidContentType:
- LOG.debug(_("Unable to read body as provided Content-Type"))
+ LOG.debug(_("Unable to deserialize body as provided Content-Type"))
raise
return deserializer.deserialize(request.body, action)
diff --git a/nova/tests/api/openstack/test_wsgi.py b/nova/tests/api/openstack/test_wsgi.py
index 7ab39ed5a..938637207 100644
--- a/nova/tests/api/openstack/test_wsgi.py
+++ b/nova/tests/api/openstack/test_wsgi.py
@@ -18,7 +18,8 @@ class RequestTest(test.TestCase):
request = wsgi.Request.blank('/tests/123', method='POST')
request.headers["Content-Type"] = "text/html"
request.body = "asdf<br />"
- self.assertEqual(request.get_content_type(), None)
+ self.assertRaises(exception.InvalidContentType,
+ request.get_content_type)
def test_content_type_with_charset(self):
request = wsgi.Request.blank('/tests/123')