summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDolph Mathews <dolph.mathews@gmail.com>2012-01-20 14:22:20 -0600
committerDolph Mathews <dolph.mathews@gmail.com>2012-01-20 14:22:55 -0600
commitf2726df39c3ec4e50448361e3be4cfba45e4fa93 (patch)
tree2d07d0ffa5f420ce59c4827e2e40750bbc4fac8a
parentfc9dcb4f51731dcb5e264538142a83b3f6b8752d (diff)
downloadkeystone-f2726df39c3ec4e50448361e3be4cfba45e4fa93.tar.gz
keystone-f2726df39c3ec4e50448361e3be4cfba45e4fa93.tar.xz
keystone-f2726df39c3ec4e50448361e3be4cfba45e4fa93.zip
Added Vary header to support caching (bug 913895)
Change-Id: I26dca09ace688a25cf207214808e8a9c919621c4
-rw-r--r--keystone/test/client/test_request_specs.py31
-rwxr-xr-xkeystone/utils.py4
2 files changed, 35 insertions, 0 deletions
diff --git a/keystone/test/client/test_request_specs.py b/keystone/test/client/test_request_specs.py
index 74494056..39118a07 100644
--- a/keystone/test/client/test_request_specs.py
+++ b/keystone/test/client/test_request_specs.py
@@ -2,6 +2,37 @@ import unittest2 as unittest
from keystone.test.functional import common
+class TestResponseHeaders(common.FunctionalTestCase):
+ """Tests API's response headers"""
+ use_server = True
+
+ def test_vary_header_on_error(self):
+ """A Vary header should be provided to support caching responses."""
+ r = self.admin_request(path='/tokens/not-a-valid-token',
+ assert_status=404)
+ self.assertIn('X-Auth-Token', r.getheader('Vary'))
+
+ def test_vary_header_on_admin(self):
+ """A Vary header should be provided to support caching responses."""
+ r = self.admin_request(path='/tokens/%s' % self.admin_token)
+ self.assertIn('X-Auth-Token', r.getheader('Vary'))
+
+ def test_vary_header_on_service(self):
+ """A Vary header should be provided to support caching responses."""
+ r = self.service_request(path='/tenants')
+ self.assertIn('X-Auth-Token', r.getheader('Vary'))
+
+ def test_vary_header_on_legacy(self):
+ """A Vary header should be provided to support caching responses."""
+ r = self.admin_request('1.1/tenants')
+ self.assertIn('X-Auth-Token', r.getheader('Vary'))
+
+ def test_vary_header_on_static(self):
+ """A Vary header should not be provided on a static request."""
+ r = self.service_request('2.0/')
+ self.assertEqual(None, r.getheader('Vary'))
+
+
class TestUrlHandling(common.FunctionalTestCase):
"""Tests API's global URL handling behaviors"""
use_server = True
diff --git a/keystone/utils.py b/keystone/utils.py
index 8933245c..27f704f6 100755
--- a/keystone/utils.py
+++ b/keystone/utils.py
@@ -147,6 +147,7 @@ def send_error(code, req, result):
resp = Response()
resp.headers['content-type'] = None
+ resp.headers['Vary'] = 'X-Auth-Token'
resp.status = code
if result:
@@ -168,6 +169,7 @@ def send_result(code, req, result=None):
resp = Response()
resp.headers['content-type'] = None
+ resp.headers['Vary'] = 'X-Auth-Token'
resp.status = code
if code > 399:
return resp
@@ -190,6 +192,8 @@ def send_legacy_result(code, headers):
if 'content-type' not in headers:
headers['content-type'] = "text/plain"
+ headers['Vary'] = 'X-Auth-Token'
+
resp.headers = headers
resp.status = code
if code > 399: