Commit 25cf4933 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

patch: Caching Policy Manager should respect existing cache-control response headers.

this commit fixes the following commit :
* patch : Caching Policy Manager should not override existing response headers.
parent 4e24a5ba
......@@ -39,13 +39,23 @@ def _setCacheHeaders(obj, extra_context):
content, view_name, extra_context
)
RESPONSE = REQUEST['RESPONSE']
# PATCH BEGIN: do not override existing headers
ignore_list = [y[0].lower() for y in RESPONSE.headers.iteritems()]
headers = [x for x in headers if x[0].lower() not in ignore_list]
# PATCH END
for key, value in headers:
if key == 'ETag':
RESPONSE.setHeader(key, value, literal=1)
# PATCH BEGIN: respect existing Cache-Control header if exists
if key.lower() == 'cache-control':
cache_control = RESPONSE.getHeader('cache-control')
if cache_control:
existing_key_list = \
[e.split('=', 2)[0].strip().lower() for e in \
cache_control.split(',')]
for e in value.split(','):
if e.split('=', 2)[0].strip().lower() not in existing_key_list:
cache_control += ', %s' % e.strip()
else:
cache_control = value
RESPONSE.setHeader(key, cache_control)
# PATCH END
else:
RESPONSE.setHeader(key, value)
if headers:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment