Make sure the reponse has a Content-Type

Before trying to make sure it is an HTML response
or else it can causes errors in DELETE API responses
This commit is contained in:
Roberto Rosario
2014-07-24 12:31:07 -04:00
parent a712f2e786
commit d2ae771d6a

View File

@@ -1,9 +1,12 @@
# Aliasing it for the sake of page size.
from django.utils.html import strip_spaces_between_tags as short
from django.utils.html import strip_spaces_between_tags
class SpacelessMiddleware(object):
"""
Remove spaces between tags in HTML responses to save on bandwidth
"""
def process_response(self, request, response):
if u'text/html' in response['Content-Type']:
response.content = short(response.content)
if 'text/html' in response.get('Content-Type', ''):
response.content = strip_spaces_between_tags(response.content)
return response