Django

Code

Ticket #4946: gzip_enhancements.patch

File gzip_enhancements.patch, 1.4 kB (added by colin@owlfish.com, 1 year ago)

Patch to enhance gzip middleware.

  • docs/middleware.txt

    old new  
    8989------------------------------------- 
    9090 
    9191Compresses content for browsers that understand gzip compression (all modern 
    92 browsers). 
     92browsers).  Useful for webservers that do not support applying gzip to  
     93dynamically created content (e.g. Lighttpd without mod_deflate). 
    9394 
     95Should be placed first in the middleware list so that, being a response 
     96middleware, it is execute last.  Will not compress content less than 200 bytes 
     97long, responses other than 200, javascript (for IE compatibility) or requests 
     98that do not accept gzip encoding. 
     99 
    94100django.middleware.http.ConditionalGetMiddleware 
    95101----------------------------------------------- 
    96102 
  • django/middleware/gzip.py

    old new  
    1111    on the Accept-Encoding header. 
    1212    """ 
    1313    def process_response(self, request, response): 
     14        if (response.status_code != 200 or len (response.content) < 200): 
     15            # Don't attempt gzip on small responses and 304's, etc 
     16            return response 
    1417        patch_vary_headers(response, ('Accept-Encoding',)) 
    1518         
    1619        # Avoid gzipping if we've already got a content-encoding or if the