Ticket #5047: patch_cache_controll.diff

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

svn patch

  • django/utils/cache.py

     
    2727
    2828cc_delim_re = re.compile(r'\s*,\s*')
    2929
    30 def patch_cache_control(response, **kwargs):
     30def patch_cache_control(response, rewrite = True, **kwargs):
    3131    """
    3232    This function patches the Cache-Control header by adding all
    3333    keyword arguments to it. The transformation is as follows:
    3434
     35    * If rewrite set to False, then value 'max-age' in current Cache-Control
     36      header remains untouched, otherwise it could be rewritten by value from
     37      kwargs
    3538    * All keyword parameter names are turned to lowercase, and underscores
    3639      are converted to hyphens.
    3740    * If the value of a parameter is True (exactly True, not just a
     
    5760        cc = dict([dictitem(el) for el in cc])
    5861    else:
    5962        cc = {}
     63
     64    if not rewrite and 'max-age' in cc and 'max_age' in kwargs:
     65        del kwargs['max_age']
     66
    6067    for (k,v) in kwargs.items():
    6168        cc[k.replace('_', '-')] = v
    6269    cc = ', '.join([dictvalue(el) for el in cc.items()])
     
    8491        response['Last-Modified'] = formatdate()[:26] + "GMT"
    8592    if not response.has_header('Expires'):
    8693        response['Expires'] = formatdate(time.time() + cache_timeout)[:26] + "GMT"
    87     patch_cache_control(response, max_age=cache_timeout)
     94    patch_cache_control(response, rewrite = False, max_age=cache_timeout)
    8895
    8996def add_never_cache_headers(response):
    9097    """
Back to Top