Fixed #30812 -- Made ConditionalGetMiddleware set ETag only for responses with non-empty content.
This commit is contained in:
parent
3cd3bebe89
commit
ee6b17187f
|
@ -98,7 +98,7 @@ def get_max_age(response):
|
||||||
|
|
||||||
|
|
||||||
def set_response_etag(response):
|
def set_response_etag(response):
|
||||||
if not response.streaming:
|
if not response.streaming and response.content:
|
||||||
response['ETag'] = quote_etag(hashlib.md5(response.content).hexdigest())
|
response['ETag'] = quote_etag(hashlib.md5(response.content).hexdigest())
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
|
@ -248,6 +248,10 @@ Miscellaneous
|
||||||
``/`` if not set). This change should not affect settings set to valid URLs
|
``/`` if not set). This change should not affect settings set to valid URLs
|
||||||
or absolute paths.
|
or absolute paths.
|
||||||
|
|
||||||
|
* :class:`~django.middleware.http.ConditionalGetMiddleware` no longer adds the
|
||||||
|
``ETag`` header to responses with an empty
|
||||||
|
:attr:`~django.http.HttpResponse.content`.
|
||||||
|
|
||||||
.. _deprecated-features-3.1:
|
.. _deprecated-features-3.1:
|
||||||
|
|
||||||
Features deprecated in 3.1
|
Features deprecated in 3.1
|
||||||
|
|
|
@ -452,6 +452,12 @@ class ConditionalGetMiddlewareTest(SimpleTestCase):
|
||||||
res = StreamingHttpResponse(['content'])
|
res = StreamingHttpResponse(['content'])
|
||||||
self.assertFalse(ConditionalGetMiddleware().process_response(self.req, res).has_header('ETag'))
|
self.assertFalse(ConditionalGetMiddleware().process_response(self.req, res).has_header('ETag'))
|
||||||
|
|
||||||
|
def test_no_etag_response_empty_content(self):
|
||||||
|
res = HttpResponse()
|
||||||
|
self.assertFalse(
|
||||||
|
ConditionalGetMiddleware().process_response(self.req, res).has_header('ETag')
|
||||||
|
)
|
||||||
|
|
||||||
def test_no_etag_no_store_cache(self):
|
def test_no_etag_no_store_cache(self):
|
||||||
self.resp['Cache-Control'] = 'No-Cache, No-Store, Max-age=0'
|
self.resp['Cache-Control'] = 'No-Cache, No-Store, Max-age=0'
|
||||||
self.assertFalse(ConditionalGetMiddleware().process_response(self.req, self.resp).has_header('ETag'))
|
self.assertFalse(ConditionalGetMiddleware().process_response(self.req, self.resp).has_header('ETag'))
|
||||||
|
|
Loading…
Reference in New Issue