From b908d36e89b560f6e2ba96da93e9c7f3f71778c2 Mon Sep 17 00:00:00 2001
From: Bastian Kleineidam <calvin@debian.org>
Date: Fri, 25 Jan 2008 15:38:10 +0100
Subject: Don't gzip PDF files for IE

Older IE browsers cannot open PDF files with Content-Encoding: gzip.
This patch prevents gzip encoding for PDF files.

Signed-off-by: Bastian Kleineidam <calvin@debian.org>

diff --git a/django/middleware/gzip.py b/django/middleware/gzip.py
index 62a2456..805704b 100644
--- a/django/middleware/gzip.py
+++ b/django/middleware/gzip.py
@@ -22,12 +22,13 @@ class GZipMiddleware(object):
         if response.has_header('Content-Encoding'):
             return response
 
-        # Older versions of IE have issues with gzipped javascript.
-        # See http://code.djangoproject.com/ticket/2449
-        is_ie = "msie" in request.META.get('HTTP_USER_AGENT', '').lower()
-        is_js = "javascript" in response.get('Content-Type', '').lower()
-        if is_ie and is_js:
-            return response
+        # Older versions of IE have issues with gzipped pages of certain type,
+        # eg. javascript and PDF (perhaps more, who knows).
+        # See also http://code.djangoproject.com/ticket/2449
+        if "msie" in request.META.get('HTTP_USER_AGENT', '').lower():
+            ctype = response.get('Content-Type', '').lower()
+            if "javascript" in ctype or ctype == "application/pdf":
+                return response
 
         ae = request.META.get('HTTP_ACCEPT_ENCODING', '')
         if not re_accepts_gzip.search(ae):
-- 
1.5.3.8

