diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2012-12-17 17:48:28 +0100 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2012-12-17 17:48:28 +0100 |
commit | dc187c79c01cc3386f2a6d0e1c459c567502ed04 (patch) | |
tree | 9b0cc053ab52e8b1dce28e197e2c0f0e2666b91b /module | |
parent | worked on web-ui (diff) | |
download | pyload-dc187c79c01cc3386f2a6d0e1c459c567502ed04.tar.xz |
fixes gzip middleware to do nothing when gzip is not available
Diffstat (limited to 'module')
-rw-r--r-- | module/web/middlewares.py | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/module/web/middlewares.py b/module/web/middlewares.py index 3cf49a8fc..ae0911cc3 100644 --- a/module/web/middlewares.py +++ b/module/web/middlewares.py @@ -1,7 +1,11 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -import gzip +# gzip is optional on some platform +try: + import gzip +except ImportError: + gzip = None try: from cStringIO import StringIO @@ -83,14 +87,13 @@ class GzipResponse(object): ct = header_value(headers,'content-type') ce = header_value(headers,'content-encoding') cl = header_value(headers, 'content-length') - if cl: - cl = int(cl) - else: - cl = 201 + + # don't compress on unknown size, it may be too huge + cl = int(cl) if cl else 0 if ce: self.compressible = False - elif ct and (ct.startswith('text/') or ct.startswith('application/')) \ + elif gzip is not None and ct and (ct.startswith('text/') or ct.startswith('application/')) \ and 'zip' not in ct and 200 < cl < 1024*1024: self.compressible = True headers.append(('content-encoding', 'gzip')) |