Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/laactech/django-response-compression
Combined Brotli and GZip compression for Django HTTP responses
https://github.com/laactech/django-response-compression
brotli compression django gzip http
Last synced: about 1 month ago
JSON representation
Combined Brotli and GZip compression for Django HTTP responses
- Host: GitHub
- URL: https://github.com/laactech/django-response-compression
- Owner: laactech
- License: bsd-3-clause
- Created: 2021-01-25T16:58:10.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2021-01-25T17:39:52.000Z (almost 4 years ago)
- Last Synced: 2024-10-28T15:04:04.809Z (3 months ago)
- Topics: brotli, compression, django, gzip, http
- Language: Python
- Homepage:
- Size: 19.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Django Response Compression
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/python/black)
[![License](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://github.com/laactech/django-require-login/blob/master/LICENSE.md)Combined Brotli and GZip compression for Django HTTP responses
This middleware copies Django's GZipMiddleware but adds Brotli compression. Brotli is
[supported](https://caniuse.com/?search=brotli) by most major browsers. If the request does not allow Brotli encoding,
the middleware falls back to Django's GZipMiddleware. Read Django's GZipMiddleware
[documentation](https://docs.djangoproject.com/en/dev/ref/middleware/#module-django.middleware.gzip) to understand how
this middleware works and heed the warnings.## Supported Versions
* Python 3.6, 3.7, 3.8, 3.9
* Django 2.2, 3.0, 3.1## Installation and Setup
Install via pip.
```sh
pip install django-response-compression
```Add the `ResponseCompressionMiddleware` to your Django middleware:
```python
MIDDLEWARE = [
# ...
'response_compression.middleware.ResponseCompressionMiddleware',
# ...
]
```Remove Django's GZipMiddleware if you added it.
**Read the GZipMiddleware [documentation](https://docs.djangoproject.com/en/dev/ref/middleware/#module-django.middleware.gzip)
for notes about middleware ordering**If you want to compress specific responses, use the decorator on your views.
```python
from response_compression.decorators import compress_response@compress_response
def my_view(request):
...
```Both the middleware and decorator are compatible with Django REST Framework responses.
The default brotli compression level is 4, and you can customize the brotli compression level by adding this to
django's settings:```python
RESPONSE_COMPRESSION_BROTLI_LEVEL = 5
```## Security
If you believe you've found a bug with security implications, please do not disclose this
issue in a public forum.Email us at [[email protected]](mailto:[email protected])
## Contribute
See [CONTRIBUTING.md](https://github.com/laactech/django-response-compression/blob/master/CONTRIBUTING.md)