summaryrefslogtreecommitdiff
path: root/django/middleware/gzip.py
diff options
context:
space:
mode:
authorGary Wilson Jr <gary.wilson@gmail.com>2007-11-19 03:41:46 +0000
committerGary Wilson Jr <gary.wilson@gmail.com>2007-11-19 03:41:46 +0000
commit5870ffd4b04c9a65ea34e1e6c794cb21b6715126 (patch)
tree1385b6e13ee06aa2394cdf1c240adcae8b3f0385 /django/middleware/gzip.py
parent34cc21983ce0124a94d01120431f35ac0653c60f (diff)
Made some stylistic changes in `GZipMiddleware` and added some notes about IE, refs #5313.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@6697 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/middleware/gzip.py')
-rw-r--r--django/middleware/gzip.py18
1 files changed, 11 insertions, 7 deletions
diff --git a/django/middleware/gzip.py b/django/middleware/gzip.py
index aa2a8ea5a6..62a2456b97 100644
--- a/django/middleware/gzip.py
+++ b/django/middleware/gzip.py
@@ -1,4 +1,5 @@
import re
+
from django.utils.text import compress_string
from django.utils.cache import patch_vary_headers
@@ -11,18 +12,21 @@ class GZipMiddleware(object):
on the Accept-Encoding header.
"""
def process_response(self, request, response):
+ # It's not worth compressing non-OK or really short responses.
if response.status_code != 200 or len(response.content) < 200:
- # Not worth compressing really short responses or 304 status
- # responses, etc.
return response
patch_vary_headers(response, ('Accept-Encoding',))
- # Avoid gzipping if we've already got a content-encoding or if the
- # content-type is Javascript and the user's browser is IE.
- is_js = ("msie" in request.META.get('HTTP_USER_AGENT', '').lower() and
- "javascript" in response.get('Content-Type', '').lower())
- if response.has_header('Content-Encoding') or is_js:
+ # Avoid gzipping if we've already got a content-encoding.
+ 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
ae = request.META.get('HTTP_ACCEPT_ENCODING', '')