From e537b10b396ebd526eb523e6be24bd692682a297 Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 14 Oct 2024 08:30:45 +0200 Subject: [PATCH] Expand mimetype defaults --- README.md | 2 +- flask_compress/flask_compress.py | 28 ++++++++++++++++++++++++---- tests/test_flask_compress.py | 28 ++++++++++++++++++++++++---- 3 files changed, 49 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 2d37957..e4369f9 100644 --- a/README.md +++ b/README.md @@ -128,7 +128,7 @@ Within your Flask application's settings you can provide the following settings | Option | Description | Default | | ------ | ----------- | ------- | -| `COMPRESS_MIMETYPES` | Set the list of mimetypes to compress here. | `[`
`'application/javascript',`
`'application/json',`
`'text/css',`
`'text/html',`
`'text/javascript',`
`'text/xml',`
`]` | +| `COMPRESS_MIMETYPES` | Set the list of mimetypes to compress here. | `[`
`'text/html',`
`'text/css',`
`'text/plain',`
`'text/xml',`
`'text/x-component',`
`'text/javascript',`
`'application/x-javascript',`
`'application/javascript',`
`'application/json',`
`'application/manifest+json',`
`'application/vnd.api+json',`
`'application/xml',`
`'application/xhtml+xml',`
`'application/rss+xml',`
`'application/atom+xml',`
`'application/vnd.ms-fontobject',`
`'application/x-font-ttf',`
`'application/x-font-opentype',`
`'application/x-font-truetype',`
`'image/svg+xml',`
`'image/x-icon',`
`'image/vnd.microsoft.icon',`
`'font/ttf',`
`'font/eot',`
`'font/otf',`
`'font/opentype',`
`]` | | `COMPRESS_LEVEL` | Specifies the gzip compression level. | `6` | | `COMPRESS_BR_LEVEL` | Specifies the Brotli compression level. Ranges from 0 to 11. | `4` | | `COMPRESS_BR_MODE` | For Brotli, the compression mode. The options are 0, 1, or 2. These correspond to "generic", "text" (for UTF-8 input), and "font" (for WOFF 2.0). | `0` | diff --git a/flask_compress/flask_compress.py b/flask_compress/flask_compress.py index 2db1971..7136450 100644 --- a/flask_compress/flask_compress.py +++ b/flask_compress/flask_compress.py @@ -46,12 +46,32 @@ def init_app(self, app): ( "COMPRESS_MIMETYPES", [ - "application/javascript", # Obsolete (RFC 9239) - "application/json", - "text/css", "text/html", - "text/javascript", + "text/css", + "text/plain", "text/xml", + "text/x-component", + "text/javascript", # Obsolete (RFC 9239) + "application/x-javascript", + "application/javascript", + "application/json", + "application/manifest+json", + "application/vnd.api+json", + "application/xml", + "application/xhtml+xml", + "application/rss+xml", + "application/atom+xml", + "application/vnd.ms-fontobject", + "application/x-font-ttf", + "application/x-font-opentype", + "application/x-font-truetype", + "image/svg+xml", + "image/x-icon", + "image/vnd.microsoft.icon", + "font/ttf", + "font/eot", + "font/otf", + "font/opentype", ], ), ("COMPRESS_LEVEL", 6), diff --git a/tests/test_flask_compress.py b/tests/test_flask_compress.py index 6874eb0..0b4e1d4 100644 --- a/tests/test_flask_compress.py +++ b/tests/test_flask_compress.py @@ -19,12 +19,32 @@ def setUp(self): def test_mimetypes_default(self): """Tests COMPRESS_MIMETYPES default value is correctly set.""" defaults = [ - "application/javascript", - "application/json", - "text/css", "text/html", - "text/javascript", + "text/css", + "text/plain", "text/xml", + "text/x-component", + "text/javascript", # Obsolete (RFC 9239) + "application/x-javascript", + "application/javascript", + "application/json", + "application/manifest+json", + "application/vnd.api+json", + "application/xml", + "application/xhtml+xml", + "application/rss+xml", + "application/atom+xml", + "application/vnd.ms-fontobject", + "application/x-font-ttf", + "application/x-font-opentype", + "application/x-font-truetype", + "image/svg+xml", + "image/x-icon", + "image/vnd.microsoft.icon", + "font/ttf", + "font/eot", + "font/otf", + "font/opentype", ] self.assertEqual(self.app.config["COMPRESS_MIMETYPES"], defaults)