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

Django 2.1 support & DOCTYPE Bug fix #131

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
20 changes: 14 additions & 6 deletions htmlmin/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,23 @@ def process_request(self, request):

class HtmlMinifyMiddleware(object):

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



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

self.process_response(request, response)


if 'text/html' in response.get('Content-Type', ''):
try:
match = re.search(r'charset=([^;\s]+)', response['Content-Type'])
encoding = match.group(1) if match else 'utf-8'
response.content = str(htmlmin.minify(response.content.decode(encoding)),
remove_comments=True,
remove_empty_space=True,
pre_tags=(u'pre', u'code', u'textarea'))
except Exception as e:
logger(e)

return response

def can_minify_response(self, request, response):
Expand Down