Ticket #16035: patch_for_16035.diff
File patch_for_16035.diff, 2.8 KB (added by , 13 years ago) |
---|
-
django/middleware/gzip.py
diff --git a/django/middleware/gzip.py b/django/middleware/gzip.py index 39ec624..cc26712 100644
a b class GZipMiddleware(object): 37 37 if len(compressed_content) >= len(response.content): 38 38 return response 39 39 40 if response.has_header('ETag'): 41 response['ETag'] = re.sub('"$', ';gzip"', response['ETag']) 42 40 43 response.content = compressed_content 41 44 response['Content-Encoding'] = 'gzip' 42 45 response['Content-Length'] = str(len(response.content)) -
tests/regressiontests/middleware/tests.py
diff --git a/tests/regressiontests/middleware/tests.py b/tests/regressiontests/middleware/tests.py index 50cb81d..f54fbb8 100644
a b from django.middleware.common import CommonMiddleware 14 14 from django.middleware.http import ConditionalGetMiddleware 15 15 from django.middleware.gzip import GZipMiddleware 16 16 from django.test import TestCase 17 17 from django.test.utils import override_settings 18 18 19 19 class CommonMiddlewareTest(TestCase): 20 20 def setUp(self): … … class GZipMiddlewareTest(TestCase): 582 582 r = GZipMiddleware().process_response(self.req, self.resp) 583 583 self.assertEqual(r.content, self.uncompressible_string) 584 584 self.assertEqual(r.get('Content-Encoding'), None) 585 586 587 @override_settings(USE_ETAGS=True) 588 class ETagGZipMiddlewareTest(TestCase): 589 """ 590 Tests if the ETag middleware behaves correctly with GZip middleware. 591 """ 592 compressible_string = 'a' * 500 593 594 def _get_request(self): 595 req = HttpRequest() 596 req.META = { 597 'SERVER_NAME': 'testserver', 598 'SERVER_PORT': 80, 599 } 600 req.path = req.path_info = "/" 601 req.META['HTTP_ACCEPT_ENCODING'] = 'gzip, deflate' 602 req.META['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Windows NT 5.1; rv:9.0.1) Gecko/20100101 Firefox/9.0.1' 603 return req 604 605 def _get_response(self): 606 resp = HttpResponse() 607 resp.status_code = 200 608 resp.content = self.compressible_string 609 resp['Content-Type'] = 'text/html; charset=UTF-8' 610 return resp 611 612 def test_compress_response(self): 613 """ 614 Tests that ETag is changed after gzip compression is performed. 615 """ 616 req = self._get_request() 617 resp = self._get_response() 618 r = GZipMiddleware().process_response(req, 619 CommonMiddleware().process_response(req, resp)) 620 gzip_etag = r.get('ETag') 621 622 req = self._get_request() 623 req.META['HTTP_ACCEPT_ENCODING'] = '' 624 resp = self._get_response() 625 r = GZipMiddleware().process_response(req, 626 CommonMiddleware().process_response(req, resp)) 627 nogzip_etag = r.get('ETag') 628 629 self.assertNotEqual(gzip_etag, nogzip_etag)