mirror of
https://github.com/django/django.git
synced 2025-10-24 22:26:08 +00:00
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.
This commit is contained in:
committed by
Tim Graham
parent
816eae3508
commit
ad332e5ca9
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user