A simple replacement for Django's default GZipMiddleware which breaks when trying to serve files or pass any kind of iterators to the HttpResponse object.
Simply replace GZipMiddleware with the provided middleware and set response.dontgzip = True when returning the response, and it will then be ignored by the middleware.
1 2 3 4 5 6 7 | from django.middleware.gzip import GZipMiddleware
class FixedGZipMiddleware(GZipMiddleware):
def process_response(self, request, response):
if hasattr(response, 'dontgzip'):
return response
return GZipMiddleware.process_response(self, request, response)
|
More like this
- find even number by Rajeev529 1 month, 3 weeks ago
- Form field with fixed value by roam 2 months, 1 week ago
- New Snippet! by Antoliny0919 2 months, 2 weeks ago
- Add Toggle Switch Widget to Django Forms by OgliariNatan 5 months, 1 week ago
- get_object_or_none by azwdevops 9 months ago
Comments
Please login first before commenting.