From dc187c79c01cc3386f2a6d0e1c459c567502ed04 Mon Sep 17 00:00:00 2001
From: RaNaN <Mast3rRaNaN@hotmail.de>
Date: Mon, 17 Dec 2012 17:48:28 +0100
Subject: fixes gzip middleware to do nothing when gzip is not available

---
 module/web/middlewares.py | 15 +++++++++------
 1 file 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'))
-- 
cgit v1.2.3