summaryrefslogtreecommitdiff
path: root/django/middleware
diff options
context:
space:
mode:
authorKevin Christopher Henry <k@severian.com>2016-10-11 03:42:00 -0400
committerTim Graham <timograham@gmail.com>2016-10-13 14:22:54 -0400
commitad332e5ca9503bba2e14cc8c3ca675eed56d72bc (patch)
tree4cf3ea2b0c921d10cfe001702227b9eb86bf6f57 /django/middleware
parent816eae35084a69a76e45439df20f69c7e0ccaef9 (diff)
Refs #19705 -- Made GZipMiddleware make ETags weak.
Django's conditional request processing can now produce 304 Not Modified responses for content that is subject to compression.
Diffstat (limited to 'django/middleware')
-rw-r--r--django/middleware/gzip.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/django/middleware/gzip.py b/django/middleware/gzip.py
index 642e3188d3..d6e2134f17 100644
--- a/django/middleware/gzip.py
+++ b/django/middleware/gzip.py
@@ -41,8 +41,12 @@ class GZipMiddleware(MiddlewareMixin):
response.content = compressed_content
response['Content-Length'] = str(len(response.content))
- if response.has_header('ETag'):
- response['ETag'] = re.sub('"$', ';gzip"', response['ETag'])
+ # If there is a strong ETag, make it weak to fulfill the requirements
+ # of RFC 7232 section-2.1 while also allowing conditional request
+ # matches on ETags.
+ etag = response.get('ETag')
+ if etag and etag.startswith('"'):
+ response['ETag'] = 'W/' + etag
response['Content-Encoding'] = 'gzip'
return response