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

Fix 500 responses on StreamingHttpResponse modifying. #145

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
21 changes: 13 additions & 8 deletions htmlmin/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import re

from django.conf import settings
from django.http.response import StreamingHttpResponse

from htmlmin.minify import html_minify

Expand All @@ -13,13 +14,13 @@ class MarkRequestMiddleware(object):

def __init__(self, get_response = None):
self.get_response = get_response


def __call__(self, request):
self.process_request(request)

response = self.get_response(request)

return response

def process_request(self, request):
Expand All @@ -30,16 +31,20 @@ class HtmlMinifyMiddleware(object):

def __init__(self, get_response = None):
self.get_response = get_response


def __call__(self, request):
response = self.get_response(request)

self.process_response(request, response)

return response

def can_minify_response(self, request, response):
if isinstance(response, StreamingHttpResponse):
# Small fix attribute error on StreamingHttpResponse handling.
return False

try:
req_ok = request._hit_htmlmin
except AttributeError:
Expand Down