Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
  • Loading branch information...
commit 66576c285a66fe5bbdb3f99cdc95f2989aea81f1 1 parent 5870ffd
@gdub gdub authored
Showing with 12 additions and 7 deletions.
  1. +12 −7 django/utils/cache.py
View
19 django/utils/cache.py
@@ -20,6 +20,10 @@
import md5
import re
import time
+try:
+ set
+except NameError:
+ from sets import Set as set # Python 2.3 fallback
from django.conf import settings
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
# implementations may rely on the order of the Vary contents in, say,
# computing an MD5 hash.
- vary = []
if response.has_header('Vary'):
- vary = cc_delim_re.split(response['Vary'])
- oldheaders = dict([(el.lower(), 1) for el in vary])
- for newheader in newheaders:
- if not newheader.lower() in oldheaders:
- vary.append(newheader)
- response['Vary'] = ', '.join(vary)
+ vary_headers = cc_delim_re.split(response['Vary'])
+ else:
+ vary_headers = []
+ # Use .lower() here so we treat headers as case-insensitive.
+ existing_headers = set([header.lower() for header in vary_headers])
+ 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):
"""Returns a cache key from the headers given in the header list."""
Please sign in to comment.
Something went wrong with that request. Please try again.