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
|
cache_timeout = settings.CACHE_MIDDLEWARE_SECONDS
|
||||||
if cache_timeout < 0:
|
if cache_timeout < 0:
|
||||||
cache_timeout = 0 # Can't have max-age negative
|
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()
|
response['ETag'] = '"%s"' % md5_constructor(response.content).hexdigest()
|
||||||
if not response.has_header('Last-Modified'):
|
if not response.has_header('Last-Modified'):
|
||||||
response['Last-Modified'] = http_date()
|
response['Last-Modified'] = http_date()
|
||||||
|
|
|
@ -1825,8 +1825,9 @@ USE_ETAGS
|
||||||
Default: ``False``
|
Default: ``False``
|
||||||
|
|
||||||
A boolean that specifies whether to output the "Etag" header. This saves
|
A boolean that specifies whether to output the "Etag" header. This saves
|
||||||
bandwidth but slows down performance. This is only used if ``CommonMiddleware``
|
bandwidth but slows down performance. This is used by the ``CommonMiddleware``
|
||||||
is installed (see :doc:`/topics/http/middleware`).
|
(see :doc:`/topics/http/middleware`) and in the``Cache Framework``
|
||||||
|
(see :doc:`/topics/cache`).
|
||||||
|
|
||||||
.. setting:: USE_I18N
|
.. setting:: USE_I18N
|
||||||
|
|
||||||
|
|
|
@ -1048,6 +1048,7 @@ class CacheI18nTest(unittest.TestCase):
|
||||||
settings.CACHE_MIDDLEWARE_SECONDS = 60
|
settings.CACHE_MIDDLEWARE_SECONDS = 60
|
||||||
settings.CACHE_MIDDLEWARE_KEY_PREFIX="test"
|
settings.CACHE_MIDDLEWARE_KEY_PREFIX="test"
|
||||||
settings.CACHE_BACKEND='locmem:///'
|
settings.CACHE_BACKEND='locmem:///'
|
||||||
|
settings.USE_ETAGS = True
|
||||||
settings.USE_I18N = True
|
settings.USE_I18N = True
|
||||||
en_message ="Hello world!"
|
en_message ="Hello world!"
|
||||||
es_message ="Hola mundo!"
|
es_message ="Hola mundo!"
|
||||||
|
@ -1058,6 +1059,14 @@ class CacheI18nTest(unittest.TestCase):
|
||||||
# Check that we can recover the cache
|
# Check that we can recover the cache
|
||||||
self.assertNotEqual(get_cache_data.content, None)
|
self.assertNotEqual(get_cache_data.content, None)
|
||||||
self.assertEqual(en_message, get_cache_data.content)
|
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
|
# change the session language and set content
|
||||||
request = self._get_request_cache()
|
request = self._get_request_cache()
|
||||||
set_cache(request, 'es', es_message)
|
set_cache(request, 'es', es_message)
|
||||||
|
|
Loading…
Reference in New Issue