Repository: colour-science/flask-compress

Issue:
gzip not work with v1.12
I am not sure what happened.
The gzip compress of my website works fine in `v1.11`.
However, in `v1.12` all files are uncompressed.

My usecase is basic as follows, where my static files locate in `/web` directory.
```
app = Flask(__name__, static_folder='web', static_url_path='')

app.config['COMPRESS_MIMETYPES'] = ['text/html', 'text/css', 'text/xml', 
                                    'application/json',
                                    'application/javascript', 'font/ttf', 'font/otf', 'application/octet-stream']

Compress(app)
```

Comments:

Patch:
diff --git a/.gitignore b/.gitignore
index a57a25f..715ed9a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,6 +3,7 @@
 *.sw[klmnop]
 # python
 *.py[co~]
+.python-version
 # Ignoring build dir
 /build
 /dist
diff --git a/README.md b/README.md
index 842b52e..4265ceb 100644
--- a/README.md
+++ b/README.md
@@ -114,3 +114,4 @@ Within your Flask application's settings you can provide the following settings
 | `COMPRESS_CACHE_BACKEND` | Specified the backend for storing the cached response data. | `None` |
 | `COMPRESS_REGISTER` | Specifies if compression should be automatically registered. | `True` |
 | `COMPRESS_ALGORITHM` | Supported compression algorithms. | `['br', 'gzip', 'deflate']` |
+| `COMPRESS_STREAMS` | Compress content streams. | `True` |
diff --git a/flask_compress/flask_compress.py b/flask_compress/flask_compress.py
index 8f01287..b1bbc0f 100644
--- a/flask_compress/flask_compress.py
+++ b/flask_compress/flask_compress.py
@@ -77,6 +77,7 @@ class Compress(object):
             ('COMPRESS_CACHE_KEY', None),
             ('COMPRESS_CACHE_BACKEND', None),
             ('COMPRESS_REGISTER', True),
+            ('COMPRESS_STREAMS', True),
             ('COMPRESS_ALGORITHM', ['br', 'gzip', 'deflate']),
         ]
 
@@ -178,7 +179,7 @@ class Compress(object):
             response.mimetype not in app.config["COMPRESS_MIMETYPES"] or
             response.status_code < 200 or
             response.status_code >= 300 or
-            response.is_streamed or
+            (response.is_streamed and app.config["COMPRESS_STREAMS"] is False)or
             "Content-Encoding" in response.headers or
             (response.content_length is not None and
              response.content_length < app.config["COMPRESS_MIN_SIZE"])):


Test patch:
diff --git a/tests/test_flask_compress.py b/tests/test_flask_compress.py
index 84a8d75..04e1051 100644
--- a/tests/test_flask_compress.py
+++ b/tests/test_flask_compress.py
@@ -51,6 +51,10 @@ class DefaultsTest(unittest.TestCase):
         """ Tests COMPRESS_BR_BLOCK default value is correctly set. """
         self.assertEqual(self.app.config['COMPRESS_BR_BLOCK'], 0)
 
+    def test_stream(self):
+        """ Tests COMPRESS_STREAMS default value is correctly set. """
+        self.assertEqual(self.app.config['COMPRESS_STREAMS'], True)
+
 class InitTests(unittest.TestCase):
     def setUp(self):
         self.app = Flask(__name__)
@@ -353,13 +357,12 @@ class StreamTests(unittest.TestCase):
     def setUp(self):
         self.app = Flask(__name__)
         self.app.testing = True
+        self.app.config["COMPRESS_STREAMS"] = False
 
         self.file_path = os.path.join(os.getcwd(), 'tests', 'templates',
                                       'large.html')
         self.file_size = os.path.getsize(self.file_path)
 
-        Compress(self.app)
-
         @self.app.route('/stream/large')
         def stream():
             def _stream():
@@ -370,6 +373,7 @@ class StreamTests(unittest.TestCase):
 
     def test_no_compression_stream(self):
         """ Tests compression is skipped when response is streamed"""
+        Compress(self.app)
         client = self.app.test_client()
         for algorithm in ('gzip', 'deflate', 'br', ''):
             headers = [('Accept-Encoding', algorithm)]
@@ -378,6 +382,17 @@ class StreamTests(unittest.TestCase):
             self.assertEqual(response.is_streamed, True)
             self.assertEqual(self.file_size, len(response.data))
 
+    def test_disabled_stream(self):
+        """Test that stream compression can be disabled."""
+        Compress(self.app)
+        self.app.config["COMPRESS_STREAMS"] = True
+        client = self.app.test_client()
+        for algorithm in ('gzip', 'deflate', 'br'):
+            headers = [('Accept-Encoding', algorithm)]
+            response = client.get('/stream/large', headers=headers)
+            self.assertIn('Content-Encoding', response.headers)
+            self.assertGreater(self.file_size, len(response.data))
+
 
 if __name__ == '__main__':
     unittest.main()