Author: mtredinnick
Date: 2007-08-12 07:29:25 -0500 (Sun, 12 Aug 2007)
New Revision: 5875

Modified:
   django/trunk/django/middleware/gzip.py
   django/trunk/docs/middleware.txt
Log:
Fixed #4946 -- Added some small improvements to Gzip middleware. Thanks, [EMAIL 
PROTECTED]


Modified: django/trunk/django/middleware/gzip.py
===================================================================
--- django/trunk/django/middleware/gzip.py      2007-08-12 12:02:08 UTC (rev 
5874)
+++ django/trunk/django/middleware/gzip.py      2007-08-12 12:29:25 UTC (rev 
5875)
@@ -11,6 +11,11 @@
     on the Accept-Encoding header.
     """
     def process_response(self, request, response):
+        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

Modified: django/trunk/docs/middleware.txt
===================================================================
--- django/trunk/docs/middleware.txt    2007-08-12 12:02:08 UTC (rev 5874)
+++ django/trunk/docs/middleware.txt    2007-08-12 12:29:25 UTC (rev 5875)
@@ -91,6 +91,12 @@
 Compresses content for browsers that understand gzip compression (all modern
 browsers).
 
+It is suggested to place this first in the middleware list, so that the
+compression of the response content is the last thing that happens. Will not
+compress content bodies less than 200 bytes long, when the response code is
+something other than 200, Javascript files (for IE compatibitility), or
+responses that have the ``Content-Encoding`` header already specified.
+
 django.middleware.http.ConditionalGetMiddleware
 -----------------------------------------------
 


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to