Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #14103 -- Take USE_ETAGS setting into account when patching the…

… response headers. Thanks, trbs and Eric Holscher.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@14885 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit dad28e8557203c8c104354cbac0349bfba5cba77 1 parent 8dfd3df
@jezdez jezdez authored
View
2  django/utils/cache.py
@@ -101,7 +101,7 @@ def patch_response_headers(response, cache_timeout=None):
cache_timeout = settings.CACHE_MIDDLEWARE_SECONDS
if cache_timeout < 0:
cache_timeout = 0 # Can't have max-age negative
- if not response.has_header('ETag'):
+ if settings.USE_ETAGS and not response.has_header('ETag'):
response['ETag'] = '"%s"' % md5_constructor(response.content).hexdigest()
if not response.has_header('Last-Modified'):
response['Last-Modified'] = http_date()
View
5 docs/ref/settings.txt
@@ -1825,8 +1825,9 @@ USE_ETAGS
Default: ``False``
A boolean that specifies whether to output the "Etag" header. This saves
-bandwidth but slows down performance. This is only used if ``CommonMiddleware``
-is installed (see :doc:`/topics/http/middleware`).
+bandwidth but slows down performance. This is used by the ``CommonMiddleware``
+(see :doc:`/topics/http/middleware`) and in the``Cache Framework``
+(see :doc:`/topics/cache`).
.. setting:: USE_I18N
View
9 tests/regressiontests/cache/tests.py
@@ -1048,6 +1048,7 @@ def set_cache(request, lang, msg):
settings.CACHE_MIDDLEWARE_SECONDS = 60
settings.CACHE_MIDDLEWARE_KEY_PREFIX="test"
settings.CACHE_BACKEND='locmem:///'
+ settings.USE_ETAGS = True
settings.USE_I18N = True
en_message ="Hello world!"
es_message ="Hola mundo!"
@@ -1058,6 +1059,14 @@ def set_cache(request, lang, msg):
# Check that we can recover the cache
self.assertNotEqual(get_cache_data.content, None)
self.assertEqual(en_message, get_cache_data.content)
+ # Check that we use etags
+ self.assertTrue(get_cache_data.has_header('ETag'))
+ # Check that we can disable etags
+ settings.USE_ETAGS = False
+ request._cache_update_cache = True
+ set_cache(request, 'en', en_message)
+ get_cache_data = FetchFromCacheMiddleware().process_request(request)
+ self.assertFalse(get_cache_data.has_header('ETag'))
# change the session language and set content
request = self._get_request_cache()
set_cache(request, 'es', es_message)
Please sign in to comment.
Something went wrong with that request. Please try again.