summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDolph Mathews <dolph.mathews@gmail.com>2012-02-23 13:47:33 -0600
committerDolph Mathews <dolph.mathews@gmail.com>2012-02-27 22:22:10 -0600
commit9581809f88b953e361ef3451d410e568b606fcca (patch)
tree908a9e7d5b55860c520322cc36630347112f90ea
parente671ee726ee1c216e24c3887ced58ce70667beba (diff)
downloadkeystone-9581809f88b953e361ef3451d410e568b606fcca.tar.gz
keystone-9581809f88b953e361ef3451d410e568b606fcca.tar.xz
keystone-9581809f88b953e361ef3451d410e568b606fcca.zip
Add Vary header (bug 928057)
Change-Id: I0db0d64725824fb27cb1f9418203d962f82b00ab
-rw-r--r--keystone/common/wsgi.py16
-rw-r--r--tests/test_content_types.py9
2 files changed, 13 insertions, 12 deletions
diff --git a/keystone/common/wsgi.py b/keystone/common/wsgi.py
index d5976339..c75339f5 100644
--- a/keystone/common/wsgi.py
+++ b/keystone/common/wsgi.py
@@ -190,14 +190,7 @@ class Application(BaseApplication):
return result
elif isinstance(result, webob.exc.WSGIHTTPException):
return result
-
- response = webob.Response()
- self._serialize(response, result)
- return response
-
- def _serialize(self, response, result):
- response.content_type = 'application/json'
- response.body = json.dumps(result, cls=utils.SmarterEncoder)
+ return render_response(body=result)
def _normalize_arg(self, arg):
return str(arg).replace(':', '_').replace('-', '_')
@@ -461,13 +454,14 @@ class ExtensionRouter(Router):
def render_response(body=None, status=(200, 'OK'), headers=None):
- """Forms a WSGI response"""
+ """Forms a WSGI response."""
resp = webob.Response()
resp.status = '%s %s' % status
- resp.headerlist = headers or [('Content-Type', 'application/json')]
+ resp.headerlist = headers or [('Content-Type', 'application/json'),
+ ('Vary', 'X-Auth-Token')]
if body is not None:
- resp.body = json.dumps(body)
+ resp.body = json.dumps(body, cls=utils.SmarterEncoder)
return resp
diff --git a/tests/test_content_types.py b/tests/test_content_types.py
index 2cd7abca..6dd8a4d3 100644
--- a/tests/test_content_types.py
+++ b/tests/test_content_types.py
@@ -23,12 +23,14 @@ class RestfulTestCase(test.TestCase):
need to bypass restful conventions or access HTTP details in your test
implementation.
- Two new asserts are provided:
+ Three new asserts are provided:
* ``assertResponseSuccessful``: called automatically for every request
unless an ``expected_status`` is provided
* ``assertResponseStatus``: called instead of ``assertResponseSuccessful``,
if an ``expected_status`` is provided
+ * ``assertValidResponseHeaders``: validates that the response headers
+ appear as expected
Requests are automatically serialized according to the defined
``content_type``. Responses are automatically deserialized as well, and
@@ -91,6 +93,7 @@ class RestfulTestCase(test.TestCase):
self.assertResponseStatus(response, expected_status)
else:
self.assertResponseSuccessful(response)
+ self.assertValidResponseHeaders(response)
# Contains the response headers, body, etc
return response
@@ -123,6 +126,10 @@ class RestfulTestCase(test.TestCase):
'Status code %s is not %s, as expected)\n\n%s' %
(response.status, expected_status, response.body))
+ def assertValidResponseHeaders(self, response):
+ """Ensures that response headers appear as expected."""
+ self.assertIn('X-Auth-Token', response.getheader('Vary'))
+
def _to_content_type(self, body, headers, content_type=None):
"""Attempt to encode JSON and XML automatically."""
content_type = content_type or self.content_type