Ticket #15066: gzip-generators.diff

File gzip-generators.diff, 975 bytes (added by Andreas Sommer <AndiDog@…>, 8 years ago)

Simple patch

  • django/middleware/gzip.py

     
    11import re
     2from types import GeneratorType
    23
    34from django.utils.text import compress_string
    45from django.utils.cache import patch_vary_headers
     
    1314    """
    1415    def process_response(self, request, response):
    1516        # It's not worth compressing non-OK or really short responses.
    16         if response.status_code != 200 or len(response.content) < 200:
     17        # Responses that are streamed using a generator are not supported
     18        # here because the content length cannot be determined beforehand.
     19        if (response.status_code != 200 or
     20            isinstance(response._container, GeneratorType) or
     21            len(response.content) < 200):
    1722            return response
    1823
    1924        patch_vary_headers(response, ('Accept-Encoding',))
Back to Top