Code

Ticket #5047: patch_cache_controll.diff

File patch_cache_controll.diff, 1.5 KB (added by anonymous, 7 years ago)

svn patch

Line 
1===================================================================
2--- django/utils/cache.py       (revision 5783)
3+++ django/utils/cache.py       (working copy)
4@@ -27,11 +27,14 @@
5 
6 cc_delim_re = re.compile(r'\s*,\s*')
7 
8-def patch_cache_control(response, **kwargs):
9+def patch_cache_control(response, rewrite = True, **kwargs):
10     """
11     This function patches the Cache-Control header by adding all
12     keyword arguments to it. The transformation is as follows:
13 
14+    * If rewrite set to False, then value 'max-age' in current Cache-Control
15+      header remains untouched, otherwise it could be rewritten by value from
16+      kwargs
17     * All keyword parameter names are turned to lowercase, and underscores
18       are converted to hyphens.
19     * If the value of a parameter is True (exactly True, not just a
20@@ -57,6 +60,10 @@
21         cc = dict([dictitem(el) for el in cc])
22     else:
23         cc = {}
24+
25+    if not rewrite and 'max-age' in cc and 'max_age' in kwargs:
26+        del kwargs['max_age']
27+
28     for (k,v) in kwargs.items():
29         cc[k.replace('_', '-')] = v
30     cc = ', '.join([dictvalue(el) for el in cc.items()])
31@@ -84,7 +91,7 @@
32         response['Last-Modified'] = formatdate()[:26] + "GMT"
33     if not response.has_header('Expires'):
34         response['Expires'] = formatdate(time.time() + cache_timeout)[:26] + "GMT"
35-    patch_cache_control(response, max_age=cache_timeout)
36+    patch_cache_control(response, rewrite = False, max_age=cache_timeout)
37 
38 def add_never_cache_headers(response):
39     """