diff --git a/django/middleware/gzip.py b/django/middleware/gzip.py
index 8e88a8c..6479c08 100644
a
|
b
|
class GZipMiddleware(object):
|
12 | 12 | on the Accept-Encoding header. |
13 | 13 | """ |
14 | 14 | def process_response(self, request, response): |
15 | | # It's not worth compressing non-OK or really short responses. |
16 | | if response.status_code != 200 or len(response.content) < 200: |
| 15 | # It's not worth compressing really short responses. |
| 16 | if len(response.content) < 200: |
17 | 17 | return response |
18 | 18 | |
19 | 19 | patch_vary_headers(response, ('Accept-Encoding',)) |
diff --git a/tests/regressiontests/middleware/tests.py b/tests/regressiontests/middleware/tests.py
index 124eb19..639e1c7 100644
a
|
b
|
from django.http import HttpResponse
|
9 | 9 | from django.middleware.clickjacking import XFrameOptionsMiddleware |
10 | 10 | from django.middleware.common import CommonMiddleware |
11 | 11 | from django.middleware.http import ConditionalGetMiddleware |
| 12 | from django.middleware.gzip import GZipMiddleware |
12 | 13 | from django.test import TestCase |
13 | 14 | |
14 | 15 | |
… |
… |
class XFrameOptionsMiddlewareTest(TestCase):
|
495 | 496 | r = OtherXFrameOptionsMiddleware().process_response(HttpRequest(), |
496 | 497 | HttpResponse()) |
497 | 498 | self.assertEqual(r['X-Frame-Options'], 'DENY') |
| 499 | |
| 500 | class GZipMiddlewareTest(TestCase): |
| 501 | def _get_processed_response(self, content, status): |
| 502 | request = HttpRequest() |
| 503 | request.META = {'HTTP_ACCEPT_ENCODING': 'gzip'} |
| 504 | response = HttpResponse(content, status=status) |
| 505 | return GZipMiddleware().process_response(request, response) |
| 506 | |
| 507 | def test_short_ok_should_not_be_gzipped(self): |
| 508 | r = self._get_processed_response('hello world', status=200) |
| 509 | |
| 510 | self.assertNotIn('Content-Encoding', r) |
| 511 | |
| 512 | def test_long_ok_should_be_gzipped(self): |
| 513 | r = self._get_processed_response('hello world'*20, status=200) |
| 514 | |
| 515 | self.assertEqual(r['Content-Encoding'], 'gzip') |
| 516 | |
| 517 | def test_long_created_should_be_gzipped(self): |
| 518 | r = self._get_processed_response('hello world'*20, status=201) |
| 519 | |
| 520 | self.assertEqual(r['Content-Encoding'], 'gzip') |