Skip to content

Commit f3a9b2b

Browse files
committed
Updated middleware logic to avoid work if content-type isn't right.
If content-type isn't an HTML type, we no longer process the panels or try to adjust the content length header.
1 parent 700de5a commit f3a9b2b

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

debug_toolbar/middleware.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,14 @@ def process_response(self, request, response):
9797
)
9898
response.cookies = cookies
9999
if response.status_code == 200 and 'gzip' not in response.get('Content-Encoding', ''):
100-
for panel in self.debug_toolbars[request].panels:
101-
panel.process_response(request, response)
102100
if response['Content-Type'].split(';')[0] in _HTML_TYPES:
101+
for panel in self.debug_toolbars[request].panels:
102+
panel.process_response(request, response)
103103
response.content = replace_insensitive(
104104
smart_unicode(response.content),
105105
self.tag,
106106
smart_unicode(self.debug_toolbars[request].render_toolbar() + self.tag))
107-
if response.get('Content-Length', None):
108-
response['Content-Length'] = len(response.content)
107+
if response.get('Content-Length', None):
108+
response['Content-Length'] = len(response.content)
109109
del self.debug_toolbars[request]
110110
return response

0 commit comments

Comments
 (0)