Ticket #17834: etag.patch
File etag.patch, 1.6 KB (added by , 13 years ago) |
---|
-
django/utils/cache.py
94 94 pass 95 95 96 96 def _set_response_etag(response): 97 response['ETag'] = '"%s"' % hashlib.md5(response.content).hexdigest() 97 if response.content: 98 response['ETag'] = '"%s"' % hashlib.md5(response.content).hexdigest() 98 99 return response 99 100 100 101 def patch_response_headers(response, cache_timeout=None): -
tests/regressiontests/cache/tests.py
18 18 from django.core.cache.backends.base import (CacheKeyWarning, 19 19 InvalidCacheBackendError) 20 20 from django.db import router 21 from django.http import HttpResponse, HttpRequest, QueryDict 21 from django.http import HttpResponse, HttpRequest, QueryDict, HttpResponseRedirect 22 22 from django.middleware.cache import (FetchFromCacheMiddleware, 23 23 UpdateCacheMiddleware, CacheMiddleware) 24 24 from django.template import Template … … 1739 1739 self.assertFalse(response.has_header('ETag')) 1740 1740 response = response.render() 1741 1741 self.assertTrue(response.has_header('ETag')) 1742 # Response with empty body should not be given implicit ETag 1743 response = HttpResponseRedirect('/') 1744 patch_response_headers(response) 1745 self.assertFalse(response.has_header('ETag')) 1742 1746 1743 1747 TestWithTemplateResponse = override_settings( 1744 1748 CACHE_MIDDLEWARE_KEY_PREFIX='settingsprefix',