Index: AUTHORS
===================================================================
--- AUTHORS	(revision 17377)
+++ AUTHORS	(working copy)
@@ -109,6 +109,7 @@
     Chris Cahoon <chris.cahoon@gmail.com>
     Juan Manuel Caicedo <juan.manuel.caicedo@gmail.com>
     Trevor Caira <trevor@caira.com>
+    Aaron Cannon <cannona@gmail.com>
     Brett Cannon <brett@python.org>
     Ricardo Javier Cárdenes Medina <ricardo.cardenes@gmail.com>
     Jeremy Carbaugh <jcarbaugh@gmail.com>
Index: django/middleware/gzip.py
===================================================================
--- django/middleware/gzip.py	(revision 17377)
+++ django/middleware/gzip.py	(working copy)
@@ -4,6 +4,10 @@
 from django.utils.cache import patch_vary_headers
 
 re_accepts_gzip = re.compile(r'\bgzip\b')
+# Matches Internet Explorer versions 4, 5 and 6
+re_is_ie_456 = re.compile(r'MSIE [456]')
+# Matches netscape version 4 but not MSIE, as MSIE masquerades as Netscape
+re_is_netscape_4 = re.compile(r'^Mozilla/4(?!.*?MSIE)')
 
 class GZipMiddleware(object):
     """
@@ -16,22 +20,19 @@
         if len(response.content) < 200:
             return response
 
-        patch_vary_headers(response, ('Accept-Encoding',))
-
-        # Avoid gzipping if we've already got a content-encoding.
+                # Avoid gzipping if we've already got a content-encoding.
         if response.has_header('Content-Encoding'):
             return response
 
-        # MSIE have issues with gzipped response of various content types.
-        if "msie" in request.META.get('HTTP_USER_AGENT', '').lower():
-            ctype = response.get('Content-Type', '').lower()
-            if not ctype.startswith("text/") or "javascript" in ctype:
-                return response
-
         ae = request.META.get('HTTP_ACCEPT_ENCODING', '')
         if not re_accepts_gzip.search(ae):
             return response
 
+        # Some browsers have issues with gzipped responses
+        ua = request.META.get('HTTP_USER_AGENT', '')
+        if re_is_ie_456.search(ua) or re_is_netscape_4.search(ua):
+            return response
+
         # Return the compressed content only if it's actually shorter.
         compressed_content = compress_string(response.content)
         if len(compressed_content) >= len(response.content):
@@ -40,4 +41,5 @@
         response.content = compressed_content
         response['Content-Encoding'] = 'gzip'
         response['Content-Length'] = str(len(response.content))
+        patch_vary_headers(response, ('Accept-Encoding',))
         return response
Index: docs/ref/middleware.txt
===================================================================
--- docs/ref/middleware.txt	(revision 17377)
+++ docs/ref/middleware.txt	(working copy)
@@ -100,11 +100,10 @@
 ``Content-Encoding`` header is already set, or when the browser does not send
 an ``Accept-Encoding`` header containing ``gzip``.
 
-Content will also not be compressed when the browser is Internet Explorer and
-the ``Content-Type`` header contains ``javascript`` or starts with anything
-other than ``text/``. This is done to overcome a bug present in early versions
-of Internet Explorer which caused decompression not to be performed on certain
-content types.
+Content will also not be compressed when the browser is Internet Explorer 5 or
+6, or Netscape 4. This is done because these browsers don't properly handle
+compressed content, but request it anyway. Fortunately these browsers make up
+less than 1.5% of the browser market.
 
 GZip compression can be applied to individual views using the
 :func:`~django.views.decorators.http.gzip_page()` decorator.

Property changes on: docs\ref\middleware.txt
___________________________________________________________________
Added: svn:eol-style
   + native

Index: tests/regressiontests/middleware/tests.py
===================================================================
--- tests/regressiontests/middleware/tests.py	(revision 17377)
+++ tests/regressiontests/middleware/tests.py	(working copy)
@@ -564,16 +564,43 @@
         self.assertEqual(r.content, self.compressible_string)
         self.assertEqual(r.get('Content-Encoding'), 'deflate')
 
-    def test_no_compress_ie_js_requests(self):
+    def test_no_compress_ie5(self):
         """
-        Tests that compression isn't performed on JavaScript requests from Internet Explorer.
+        Tests that compression isn't performed on requests from Internet Explorer 5.
         """
         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)
 
+    def test_no_compress_ie6(self):
+        """
+        Tests that compression isn't performed on requests from Internet Explorer 6.
+        """
+        self.req.META['HTTP_USER_AGENT'] = 'Mozilla/4.0 (compatible; MSIE 6.1; Windows XP)'
+        r = GZipMiddleware().process_response(self.req, self.resp)
+        self.assertEqual(r.content, self.compressible_string)
+        self.assertEqual(r.get('Content-Encoding'), None)
+
+    def test_no_compress_netscape4(self):
+        """
+        Tests that compression isn't performed on requests from Netscape 4.
+        """
+        self.req.META['HTTP_USER_AGENT'] = 'Mozilla/4.8 [en] (X11; U; Linux 2.6.12-1.1372_FC3 i686; Nav)'
+        r = GZipMiddleware().process_response(self.req, self.resp)
+        self.assertEqual(r.content, self.compressible_string)
+        self.assertEqual(r.get('Content-Encoding'), None)
+
+    def test_compress_IE7(self):
+        """
+        Tests that compression is performed on requests from Internet Explorer 7.
+        IE7 sometimes masquerades as Netscape 4.
+        """
+        self.req.META['HTTP_USER_AGENT'] = 'Mozilla /4.0 (compatible;MSIE 7.0;Windows NT6.0)'
+        r = GZipMiddleware().process_response(self.req, self.resp)
+        self.assertEqual(self.decompress(r.content), self.compressible_string)
+        self.assertEqual(r.get('Content-Encoding'), 'gzip')
+
     def test_no_compress_uncompressible_response(self):
         """
         Tests that compression isn't performed on responses with uncompressible content.
