summaryrefslogtreecommitdiff
path: root/django/utils/cache.py
diff options
context:
space:
mode:
authorTom Carrick <tom@carrick.eu>2020-07-14 13:32:24 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-09-14 08:41:59 +0200
commitbcc2befd0e9c1885e45b46d0b0bcdc11def8b249 (patch)
tree59fab69a3182286da87fcd6fe05a8ce0f4277a5a /django/utils/cache.py
parent71ae1ab0123582cc5bfe0f7d5f4cc19a9412f396 (diff)
downloaddjango-bcc2befd0e9c1885e45b46d0b0bcdc11def8b249.tar.gz
Fixed #31789 -- Added a new headers interface to HttpResponse.
Diffstat (limited to 'django/utils/cache.py')
-rw-r--r--django/utils/cache.py22
1 files changed, 11 insertions, 11 deletions
diff --git a/django/utils/cache.py b/django/utils/cache.py
index 72f017f38a..0541d373ee 100644
--- a/django/utils/cache.py
+++ b/django/utils/cache.py
@@ -62,7 +62,7 @@ def patch_cache_control(response, **kwargs):
cc = defaultdict(set)
if response.get('Cache-Control'):
- for field in cc_delim_re.split(response['Cache-Control']):
+ for field in cc_delim_re.split(response.headers['Cache-Control']):
directive, value = dictitem(field)
if directive == 'no-cache':
# no-cache supports multiple field names.
@@ -100,7 +100,7 @@ def patch_cache_control(response, **kwargs):
else:
directives.append(dictvalue(directive, values))
cc = ', '.join(directives)
- response['Cache-Control'] = cc
+ response.headers['Cache-Control'] = cc
def get_max_age(response):
@@ -110,7 +110,7 @@ def get_max_age(response):
"""
if not response.has_header('Cache-Control'):
return
- cc = dict(_to_tuple(el) for el in cc_delim_re.split(response['Cache-Control']))
+ cc = dict(_to_tuple(el) for el in cc_delim_re.split(response.headers['Cache-Control']))
try:
return int(cc['max-age'])
except (ValueError, TypeError, KeyError):
@@ -119,7 +119,7 @@ def get_max_age(response):
def set_response_etag(response):
if not response.streaming and response.content:
- response['ETag'] = quote_etag(hashlib.md5(response.content).hexdigest())
+ response.headers['ETag'] = quote_etag(hashlib.md5(response.content).hexdigest())
return response
@@ -140,7 +140,7 @@ def _not_modified(request, response=None):
# Last-Modified.
for header in ('Cache-Control', 'Content-Location', 'Date', 'ETag', 'Expires', 'Last-Modified', 'Vary'):
if header in response:
- new_response[header] = response[header]
+ new_response.headers[header] = response.headers[header]
# Preserve cookies as per the cookie specification: "If a proxy server
# receives a response which contains a Set-cookie header, it should
@@ -261,7 +261,7 @@ def patch_response_headers(response, cache_timeout=None):
if cache_timeout < 0:
cache_timeout = 0 # Can't have max-age negative
if not response.has_header('Expires'):
- response['Expires'] = http_date(time.time() + cache_timeout)
+ response.headers['Expires'] = http_date(time.time() + cache_timeout)
patch_cache_control(response, max_age=cache_timeout)
@@ -284,7 +284,7 @@ def patch_vary_headers(response, newheaders):
# implementations may rely on the order of the Vary contents in, say,
# computing an MD5 hash.
if response.has_header('Vary'):
- vary_headers = cc_delim_re.split(response['Vary'])
+ vary_headers = cc_delim_re.split(response.headers['Vary'])
else:
vary_headers = []
# Use .lower() here so we treat headers as case-insensitive.
@@ -293,9 +293,9 @@ def patch_vary_headers(response, newheaders):
if newheader.lower() not in existing_headers]
vary_headers += additional_headers
if '*' in vary_headers:
- response['Vary'] = '*'
+ response.headers['Vary'] = '*'
else:
- response['Vary'] = ', '.join(vary_headers)
+ response.headers['Vary'] = ', '.join(vary_headers)
def has_vary_header(response, header_query):
@@ -304,7 +304,7 @@ def has_vary_header(response, header_query):
"""
if not response.has_header('Vary'):
return False
- vary_headers = cc_delim_re.split(response['Vary'])
+ vary_headers = cc_delim_re.split(response.headers['Vary'])
existing_headers = {header.lower() for header in vary_headers}
return header_query.lower() in existing_headers
@@ -391,7 +391,7 @@ def learn_cache_key(request, response, cache_timeout=None, key_prefix=None, cach
# in that case and would result in storing the same content under
# multiple keys in the cache. See #18191 for details.
headerlist = []
- for header in cc_delim_re.split(response['Vary']):
+ for header in cc_delim_re.split(response.headers['Vary']):
header = header.upper().replace('-', '_')
if header != 'ACCEPT_LANGUAGE' or not is_accept_language_redundant:
headerlist.append('HTTP_' + header)