1# Copyright 2013 django-htmlmin authors. All rights reserved. 2# Use of this source code is governed by a BSD-style 3# license that can be found in the LICENSE file. 4 5from functools import wraps 6 7from htmlmin.minify import html_minify 8 9 10def minified_response(f): 11 @wraps(f) 12 def minify(*args, **kwargs): 13 response = f(*args, **kwargs) 14 minifiable_status = response.status_code == 200 15 minifiable_content = 'text/html' in response['Content-Type'] 16 if minifiable_status and minifiable_content: 17 response.content = html_minify(response.content) 18 return response 19 20 return minify 21 22 23def not_minified_response(f): 24 @wraps(f) 25 def not_minify(*args, **kwargs): 26 response = f(*args, **kwargs) 27 response.minify_response = False 28 return response 29 30 return not_minify 31