Some minor changes to the `patch_vary_headers` function:
* Replaced a for loop with a list comprehension. * Used a set instead of a dict with dummy values. * Used a bit more readable variable names. git-svn-id: http://code.djangoproject.com/svn/django/trunk@6698 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
5870ffd4b0
commit
66576c285a
|
@ -20,6 +20,10 @@ An example: i18n middleware would need to distinguish caches by the
|
||||||
import md5
|
import md5
|
||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
|
try:
|
||||||
|
set
|
||||||
|
except NameError:
|
||||||
|
from sets import Set as set # Python 2.3 fallback
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.cache import cache
|
from django.core.cache import cache
|
||||||
|
@ -107,14 +111,15 @@ def patch_vary_headers(response, newheaders):
|
||||||
# Note that we need to keep the original order intact, because cache
|
# Note that we need to keep the original order intact, because cache
|
||||||
# implementations may rely on the order of the Vary contents in, say,
|
# implementations may rely on the order of the Vary contents in, say,
|
||||||
# computing an MD5 hash.
|
# computing an MD5 hash.
|
||||||
vary = []
|
|
||||||
if response.has_header('Vary'):
|
if response.has_header('Vary'):
|
||||||
vary = cc_delim_re.split(response['Vary'])
|
vary_headers = cc_delim_re.split(response['Vary'])
|
||||||
oldheaders = dict([(el.lower(), 1) for el in vary])
|
else:
|
||||||
for newheader in newheaders:
|
vary_headers = []
|
||||||
if not newheader.lower() in oldheaders:
|
# Use .lower() here so we treat headers as case-insensitive.
|
||||||
vary.append(newheader)
|
existing_headers = set([header.lower() for header in vary_headers])
|
||||||
response['Vary'] = ', '.join(vary)
|
additional_headers = [newheader for newheader in newheaders
|
||||||
|
if newheader.lower() not in existing_headers]
|
||||||
|
response['Vary'] = ', '.join(vary_headers + additional_headers)
|
||||||
|
|
||||||
def _generate_cache_key(request, headerlist, key_prefix):
|
def _generate_cache_key(request, headerlist, key_prefix):
|
||||||
"""Returns a cache key from the headers given in the header list."""
|
"""Returns a cache key from the headers given in the header list."""
|
||||||
|
|
Loading…
Reference in New Issue