diff --git a/AUTHORS b/AUTHORS index 26f0362522..08fc5fdbd5 100644 --- a/AUTHORS +++ b/AUTHORS @@ -9,6 +9,7 @@ answer newbie questions, and generally made Django that much better: Aaron Swartz Aaron T. Myers Adam Johnson + Adam Malinowski Adam Vandenberg Adrian Holovaty Adrien Lemaire diff --git a/django/middleware/http.py b/django/middleware/http.py index 41389d930e..173bb49f89 100644 --- a/django/middleware/http.py +++ b/django/middleware/http.py @@ -11,13 +11,8 @@ class ConditionalGetMiddleware(MiddlewareMixin): Last-Modified header, and the request has If-None-Match or If-Modified-Since, the response is replaced by an HttpNotModified. An ETag header is added if needed. - - Also sets the Content-Length response-header. """ def process_response(self, request, response): - 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. diff --git a/docs/ref/middleware.txt b/docs/ref/middleware.txt index 71e888e928..e118bf14ce 100644 --- a/docs/ref/middleware.txt +++ b/docs/ref/middleware.txt @@ -181,12 +181,10 @@ header, the middleware adds one if needed. If the response has a ``ETag`` or ``If-Modified-Since``, the response is replaced by an :class:`~django.http.HttpResponseNotModified`. -Also sets ``Content-Length`` response-header. - .. versionchanged:: 1.11 - In older versions, the middleware set the ``Date`` header and didn't set - the ``ETag`` header. + In older versions, the middleware set the ``Content-Length`` and ``Date`` + headers and didn't set the ``ETag`` header. Locale middleware ----------------- diff --git a/docs/releases/1.11.txt b/docs/releases/1.11.txt index 55fe3be7f6..f4781463a8 100644 --- a/docs/releases/1.11.txt +++ b/docs/releases/1.11.txt @@ -579,8 +579,10 @@ Miscellaneous * In the admin templates, ``

`` is replaced with a ``

`` tag to allow including lists inside help text. -* ``ConditionalGetMiddleware`` no longer sets the ``Date`` header as Web - servers set that header. +* :class:`~django.middleware.http.ConditionalGetMiddleware` no longer sets the + ``Date`` header as Web servers set that header. It also no longer sets the + ``Content-Length`` header as this is now done by + :class:`~django.middleware.common.CommonMiddleware`. * :meth:`~django.apps.AppConfig.get_model` and :meth:`~django.apps.AppConfig.get_models` now raise diff --git a/tests/middleware/tests.py b/tests/middleware/tests.py index 680354e956..a51c4eeb31 100644 --- a/tests/middleware/tests.py +++ b/tests/middleware/tests.py @@ -478,30 +478,6 @@ class ConditionalGetMiddlewareTest(SimpleTestCase): self.req = RequestFactory().get('/') self.resp = self.client.get(self.req.path_info) - # Tests for the Content-Length header - - def test_content_length_header_added(self): - content_length = len(self.resp.content) - # Already set by CommonMiddleware, remove it to check that - # ConditionalGetMiddleware readds it. - del self.resp['Content-Length'] - self.assertNotIn('Content-Length', self.resp) - self.resp = ConditionalGetMiddleware().process_response(self.req, self.resp) - self.assertIn('Content-Length', self.resp) - self.assertEqual(int(self.resp['Content-Length']), content_length) - - def test_content_length_header_not_added(self): - resp = StreamingHttpResponse('content') - self.assertNotIn('Content-Length', resp) - resp = ConditionalGetMiddleware().process_response(self.req, resp) - self.assertNotIn('Content-Length', resp) - - def test_content_length_header_not_changed(self): - bad_content_length = len(self.resp.content) + 10 - self.resp['Content-Length'] = bad_content_length - self.resp = ConditionalGetMiddleware().process_response(self.req, self.resp) - self.assertEqual(int(self.resp['Content-Length']), bad_content_length) - # Tests for the ETag header def test_middleware_calculates_etag(self):