Changed ETag computation to first check if an ETag header already exists in the

response.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@5483 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Malcolm Tredinnick 2007-06-17 07:21:09 +00:00
parent bccb8897e6
commit 9b397ee50d
1 changed files with 6 additions and 2 deletions

View File

@ -11,7 +11,8 @@ class CommonMiddleware(object):
- Forbids access to User-Agents in settings.DISALLOWED_USER_AGENTS
- URL rewriting: Based on the APPEND_SLASH and PREPEND_WWW settings,
this middleware appends missing slashes and/or prepends missing "www."s.
this middleware appends missing slashes and/or prepends missing
"www."s.
- ETags: If the USE_ETAGS setting is set, ETags will be calculated from
the entire page content and Not Modified responses will be returned
@ -74,6 +75,9 @@ class CommonMiddleware(object):
# Use ETags, if requested.
if settings.USE_ETAGS:
if response.has_header('ETag'):
etag = response['ETag']
else:
etag = md5.new(response.content).hexdigest()
if response.status_code >= 200 and response.status_code < 300 and request.META.get('HTTP_IF_NONE_MATCH') == etag:
response = http.HttpResponseNotModified()