Fixed #4946 -- Added some small improvements to Gzip middleware. Thanks, colin@owlfish.com.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5875 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
3757f30c99
commit
c050b6a25a
|
@ -11,6 +11,11 @@ class GZipMiddleware(object):
|
||||||
on the Accept-Encoding header.
|
on the Accept-Encoding header.
|
||||||
"""
|
"""
|
||||||
def process_response(self, request, response):
|
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',))
|
patch_vary_headers(response, ('Accept-Encoding',))
|
||||||
|
|
||||||
# Avoid gzipping if we've already got a content-encoding or if the
|
# Avoid gzipping if we've already got a content-encoding or if the
|
||||||
|
|
|
@ -91,6 +91,12 @@ django.middleware.gzip.GZipMiddleware
|
||||||
Compresses content for browsers that understand gzip compression (all modern
|
Compresses content for browsers that understand gzip compression (all modern
|
||||||
browsers).
|
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
|
django.middleware.http.ConditionalGetMiddleware
|
||||||
-----------------------------------------------
|
-----------------------------------------------
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue