summaryrefslogtreecommitdiff
path: root/django/middleware/http.py
diff options
context:
space:
mode:
Diffstat (limited to 'django/middleware/http.py')
-rw-r--r--django/middleware/http.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/django/middleware/http.py b/django/middleware/http.py
index a075ccfe79..41389d930e 100644
--- a/django/middleware/http.py
+++ b/django/middleware/http.py
@@ -18,6 +18,12 @@ class ConditionalGetMiddleware(MiddlewareMixin):
if not response.streaming and not response.has_header('Content-Length'):
response['Content-Length'] = str(len(response.content))
+ # It's too late to prevent an unsafe request with a 412 response, and
+ # for a HEAD request, the response body is always empty so computing
+ # an accurate ETag isn't possible.
+ if request.method != 'GET':
+ return response
+
if self.needs_etag(response) and not response.has_header('ETag'):
set_response_etag(response)