diff --git a/nova/api/openstack/wsgi.py b/nova/api/openstack/wsgi.py index 79382d864422..91eeef4b112b 100644 --- a/nova/api/openstack/wsgi.py +++ b/nova/api/openstack/wsgi.py @@ -588,7 +588,7 @@ class ResponseObject(object): response = webob.Response() response.status_int = self.code for hdr, value in self._headers.items(): - response.headers[hdr] = value + response.headers[hdr] = str(value) response.headers['Content-Type'] = content_type if self.obj is not None: response.body = serializer.serialize(self.obj) @@ -1150,6 +1150,8 @@ class Fault(webob.exc.HTTPException): def __init__(self, exception): """Create a Fault for the given webob.exc.exception.""" self.wrapped_exc = exception + for key, value in self.wrapped_exc.headers.items(): + self.wrapped_exc.headers[key] = str(value) self.status_int = exception.status_int @webob.dec.wsgify(RequestClass=Request) diff --git a/nova/tests/api/openstack/compute/test_api.py b/nova/tests/api/openstack/compute/test_api.py index 9061fd3974ba..da1a4eecea25 100644 --- a/nova/tests/api/openstack/compute/test_api.py +++ b/nova/tests/api/openstack/compute/test_api.py @@ -157,7 +157,7 @@ class APITest(test.TestCase): if hasattr(exception_type, 'headers'): for (key, value) in exception_type.headers.iteritems(): self.assertTrue(key in resp.headers) - self.assertEquals(resp.headers[key], value) + self.assertEquals(resp.headers[key], str(value)) def test_quota_error_mapping(self): self._do_test_exception_mapping(exception.QuotaError, 'too many used') diff --git a/nova/tests/api/openstack/test_faults.py b/nova/tests/api/openstack/test_faults.py index 1bdb9f8c6ee7..cdec44d23569 100644 --- a/nova/tests/api/openstack/test_faults.py +++ b/nova/tests/api/openstack/test_faults.py @@ -68,6 +68,8 @@ class TestFaults(test.TestCase): for request in requests: exc = webob.exc.HTTPRequestEntityTooLarge + # NOTE(aloga): we intentionally pass an integer for the + # 'Retry-After' header. It should be then converted to a str fault = wsgi.Fault(exc(explanation='sorry', headers={'Retry-After': 4})) response = request.get_response(fault) @@ -76,7 +78,7 @@ class TestFaults(test.TestCase): "overLimit": { "message": "sorry", "code": 413, - "retryAfter": 4, + "retryAfter": "4", }, } actual = jsonutils.loads(response.body) diff --git a/nova/tests/api/openstack/test_wsgi.py b/nova/tests/api/openstack/test_wsgi.py index 374aa11623f4..a19204dff9c1 100644 --- a/nova/tests/api/openstack/test_wsgi.py +++ b/nova/tests/api/openstack/test_wsgi.py @@ -867,6 +867,7 @@ class ResponseObjectTest(test.TestCase): atom=AtomSerializer) robj['X-header1'] = 'header1' robj['X-header2'] = 'header2' + robj['X-header3'] = 3 for content_type, mtype in wsgi._MEDIA_TYPE_MAP.items(): request = wsgi.Request.blank('/tests/123') @@ -875,6 +876,7 @@ class ResponseObjectTest(test.TestCase): self.assertEqual(response.headers['Content-Type'], content_type) self.assertEqual(response.headers['X-header1'], 'header1') self.assertEqual(response.headers['X-header2'], 'header2') + self.assertEqual(response.headers['X-header3'], '3') self.assertEqual(response.status_int, 202) self.assertEqual(response.body, mtype)