Ticket #8034: gzip_middleware_no_images.diff

File gzip_middleware_no_images.diff, 792 bytes (added by magneto, 16 years ago)

do not gzip image content-types

  • middleware/gzip.py

     
    44from django.utils.cache import patch_vary_headers
    55
    66re_accepts_gzip = re.compile(r'\bgzip\b')
     7NO_GZIP = re.compile(r'image')
    78
    89class GZipMiddleware(object):
    910    """
     
    1213    on the Accept-Encoding header.
    1314    """
    1415    def process_response(self, request, response):
     16        ctype = response.get('Content-Type', '').lower()
     17        if ctype and NO_GZIP.match(ctype):
     18            return response
     19           
    1520        # It's not worth compressing non-OK or really short responses.
    1621        if response.status_code != 200 or len(response.content) < 200:
    1722            return response
Back to Top