Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand mimetype defaults #57

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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