mirror of
https://github.com/django/django.git
synced 2024-12-01 15:42:04 +01:00
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
This commit is contained in:
parent
8dfd3dfd49
commit
dad28e8557
@ -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()
|
||||
|
@ -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
|
||||
|
||||
|
9
tests/regressiontests/cache/tests.py
vendored
9
tests/regressiontests/cache/tests.py
vendored
@ -1048,6 +1048,7 @@ class CacheI18nTest(unittest.TestCase):
|
||||
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 @@ class CacheI18nTest(unittest.TestCase):
|
||||
# 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)
|
||||
|
Loading…
Reference in New Issue
Block a user