summaryrefslogtreecommitdiff
path: root/django/middleware/http.py
diff options
context:
space:
mode:
authorKevin Christopher Henry <k@severian.com>2016-10-13 00:31:48 -0400
committerTim Graham <timograham@gmail.com>2016-10-17 16:11:53 -0400
commit2327fad54e334119f2561ddddf52e5af4bb14d41 (patch)
tree2184a9d21428c98ca099430eb7850670bb652509 /django/middleware/http.py
parenta4e9e834e3dfc8d5a024a78c765f193105d41a48 (diff)
Fixed #27344 -- Made ConditionalGetMiddleware only process GET requests.
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)