예제 #1
0
 def test_compress_response(self):
     """
     Tests that compression is performed on responses with compressible content.
     """
     r = GZipMiddleware().process_response(self.req, self.resp)
     self.assertEqual(self.decompress(r.content), self.compressible_string)
     self.assertEqual(r.get('Content-Encoding'), 'gzip')
     self.assertEqual(r.get('Content-Length'), str(len(r.content)))
예제 #2
0
    def test_compress_response(self):
        """
        Tests that ETag is changed after gzip compression is performed.
        """
        request = self.rf.get('/', HTTP_ACCEPT_ENCODING='gzip, deflate')
        response = GZipMiddleware().process_response(request,
            CommonMiddleware().process_response(request,
                HttpResponse(self.compressible_string)))
        gzip_etag = response.get('ETag')

        request = self.rf.get('/', HTTP_ACCEPT_ENCODING='')
        response = GZipMiddleware().process_response(request,
            CommonMiddleware().process_response(request,
                HttpResponse(self.compressible_string)))
        nogzip_etag = response.get('ETag')

        self.assertNotEqual(gzip_etag, nogzip_etag)
예제 #3
0
 def test_no_compress_uncompressible_response(self):
     """
     Tests that compression isn't performed on responses with uncompressible content.
     """
     self.resp.content = self.uncompressible_string
     r = GZipMiddleware().process_response(self.req, self.resp)
     self.assertEqual(r.content, self.uncompressible_string)
     self.assertEqual(r.get('Content-Encoding'), None)
예제 #4
0
 def test_no_compress_compressed_response(self):
     """
     Tests that compression isn't performed on responses that are already compressed.
     """
     self.resp['Content-Encoding'] = 'deflate'
     r = GZipMiddleware().process_response(self.req, self.resp)
     self.assertEqual(r.content, self.compressible_string)
     self.assertEqual(r.get('Content-Encoding'), 'deflate')
예제 #5
0
 def test_no_compress_ie_js_requests(self):
     """
     Tests that compression isn't performed on JavaScript requests from Internet Explorer.
     """
     self.req.META['HTTP_USER_AGENT'] = 'Mozilla/4.0 (compatible; MSIE 5.00; Windows 98)'
     self.resp['Content-Type'] = 'application/javascript; charset=UTF-8'
     r = GZipMiddleware().process_response(self.req, self.resp)
     self.assertEqual(r.content, self.compressible_string)
     self.assertEqual(r.get('Content-Encoding'), None)
예제 #6
0
 def test_compress_non_200_response(self):
     """
     Tests that compression is performed on responses with a status other than 200.
     See #10762.
     """
     self.resp.status_code = 404
     r = GZipMiddleware().process_response(self.req, self.resp)
     self.assertEqual(self.decompress(r.content), self.compressible_string)
     self.assertEqual(r.get('Content-Encoding'), 'gzip')