diff options
| author | Claude Paroz <claude@2xlibre.net> | 2016-06-18 10:51:38 +0200 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2016-06-27 10:44:57 +0200 |
| commit | 9588718cd404d73b2be09241b424b539d8d8c66e (patch) | |
| tree | 3ad0f2054fb540fd92ce9ae0125ed70e19eee2e8 /tests/middleware | |
| parent | ca77b509059831b055a3b735ff77e042f8e1c0eb (diff) | |
Fixed #5897 -- Added the Content-Length response header in CommonMiddleware
Thanks Tim Graham for the review.
Diffstat (limited to 'tests/middleware')
| -rw-r--r-- | tests/middleware/tests.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/middleware/tests.py b/tests/middleware/tests.py index f87bb9d71c..f9ef951b44 100644 --- a/tests/middleware/tests.py +++ b/tests/middleware/tests.py @@ -285,6 +285,27 @@ class CommonMiddlewareTest(SimpleTestCase): second_res = CommonMiddleware().process_response(second_req, HttpResponse('content')) self.assertEqual(second_res.status_code, 304) + # Tests for the Content-Length header + + def test_content_length_header_added(self): + response = HttpResponse('content') + self.assertNotIn('Content-Length', response) + response = CommonMiddleware().process_response(HttpRequest(), response) + self.assertEqual(int(response['Content-Length']), len(response.content)) + + def test_content_length_header_not_added_for_streaming_response(self): + response = StreamingHttpResponse('content') + self.assertNotIn('Content-Length', response) + response = CommonMiddleware().process_response(HttpRequest(), response) + self.assertNotIn('Content-Length', response) + + def test_content_length_header_not_changed(self): + response = HttpResponse() + bad_content_length = len(response.content) + 10 + response['Content-Length'] = bad_content_length + response = CommonMiddleware().process_response(HttpRequest(), response) + self.assertEqual(int(response['Content-Length']), bad_content_length) + # Other tests @override_settings(DISALLOWED_USER_AGENTS=[re.compile(r'foo')]) @@ -445,6 +466,9 @@ class ConditionalGetMiddlewareTest(SimpleTestCase): 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) |
