From d2ae771d6a214cd3f09046d7cf0aa9e7c3183ed2 Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Thu, 24 Jul 2014 12:31:07 -0400 Subject: [PATCH] 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 --- .../apps/common/middleware/strip_spaces_widdleware.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/mayan/apps/common/middleware/strip_spaces_widdleware.py b/mayan/apps/common/middleware/strip_spaces_widdleware.py index eb75e7f597..ddfa4edf52 100644 --- a/mayan/apps/common/middleware/strip_spaces_widdleware.py +++ b/mayan/apps/common/middleware/strip_spaces_widdleware.py @@ -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