Skip to content

Commit

Permalink
Expand mimetype defaults (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexprengere authored Oct 14, 2024
1 parent f3cba56 commit 541aab5
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. | `[`<br>`'application/javascript',`<br>`'application/json',`<br>`'text/css',`<br>`'text/html',`<br>`'text/javascript',`<br>`'text/xml',`<br>`]` |
| `COMPRESS_MIMETYPES` | Set the list of mimetypes to compress here. | `[`<br>`'text/html',`<br>`'text/css',`<br>`'text/plain',`<br>`'text/xml',`<br>`'text/x-component',`<br>`'text/javascript',`<br>`'application/x-javascript',`<br>`'application/javascript',`<br>`'application/json',`<br>`'application/manifest+json',`<br>`'application/vnd.api+json',`<br>`'application/xml',`<br>`'application/xhtml+xml',`<br>`'application/rss+xml',`<br>`'application/atom+xml',`<br>`'application/vnd.ms-fontobject',`<br>`'application/x-font-ttf',`<br>`'application/x-font-opentype',`<br>`'application/x-font-truetype',`<br>`'image/svg+xml',`<br>`'image/x-icon',`<br>`'image/vnd.microsoft.icon',`<br>`'font/ttf',`<br>`'font/eot',`<br>`'font/otf',`<br>`'font/opentype',`<br>`]` |
| `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` |
Expand Down
28 changes: 24 additions & 4 deletions flask_compress/flask_compress.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
28 changes: 24 additions & 4 deletions tests/test_flask_compress.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 541aab5

Please sign in to comment.