Django

Code

Show
Ignore:
Timestamp:
11/18/07 21:41:46 (1 year ago)
Author:
gwilson
Message:

Made some stylistic changes in GZipMiddleware and added some notes about IE, refs #5313.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/middleware/gzip.py

    r6538 r6697  
    11import re 
     2 
    23from django.utils.text import compress_string 
    34from django.utils.cache import patch_vary_headers 
     
    1213    """ 
    1314    def process_response(self, request, response): 
     15        # It's not worth compressing non-OK or really short responses. 
    1416        if response.status_code != 200 or len(response.content) < 200: 
    15             # Not worth compressing really short responses or 304 status 
    16             # responses, etc. 
    1717            return response 
    1818 
    1919        patch_vary_headers(response, ('Accept-Encoding',)) 
    2020 
    21         # Avoid gzipping if we've already got a content-encoding or if the 
    22         # content-type is Javascript and the user's browser is IE. 
    23         is_js = ("msie" in request.META.get('HTTP_USER_AGENT', '').lower() and 
    24                 "javascript" in response.get('Content-Type', '').lower()) 
    25         if response.has_header('Content-Encoding') or is_js: 
     21        # Avoid gzipping if we've already got a content-encoding. 
     22        if response.has_header('Content-Encoding'): 
     23            return response 
     24 
     25        # Older versions of IE have issues with gzipped javascript. 
     26        # See http://code.djangoproject.com/ticket/2449 
     27        is_ie = "msie" in request.META.get('HTTP_USER_AGENT', '').lower() 
     28        is_js = "javascript" in response.get('Content-Type', '').lower() 
     29        if is_ie and is_js: 
    2630            return response 
    2731