@@ -15,7 +15,9 @@ def __init__(self, get_response):
15
15
def __call__ (self , request ):
16
16
"""Process the response and strip extra newlines from HTML."""
17
17
response = self .get_response (request )
18
- is_html = response ["Content-Type" ] == "text/html" or response ["Content-Type" ].startswith ("text/html;" )
18
+ is_html = (
19
+ response ["Content-Type" ] == "text/html" or response ["Content-Type" ].startswith ("text/html;" ) if "Content-Type" in response else False
20
+ ) # noqa: E501 pylint: disable=line-too-long
19
21
if is_html and settings .DEBUG :
20
22
response .content = re .sub (r"\n(\s*)\n" , "\n " , response .content .decode ())
21
23
response .content = re .sub (r"^(\s*)\n" , "" , response .content .decode ())
@@ -35,7 +37,9 @@ def __init__(self, get_response):
35
37
36
38
def __call__ (self , request ):
37
39
response = self .get_response (request )
38
- is_html = response ["Content-Type" ] == "text/html" or response ["Content-Type" ].startswith ("text/html;" )
40
+ is_html = (
41
+ response ["Content-Type" ] == "text/html" or response ["Content-Type" ].startswith ("text/html;" ) if "Content-Type" in response else False
42
+ ) # noqa: E501 pylint: disable=line-too-long
39
43
if is_html and request .path .startswith ("/eighth/admin" ):
40
44
replacement = """</select>
41
45
<div class="selectize-control selectize-loading">
@@ -57,7 +61,9 @@ def __init__(self, get_response):
57
61
58
62
def __call__ (self , request ):
59
63
response = self .get_response (request )
60
- is_html = response ["Content-Type" ] == "text/html" or response ["Content-Type" ].startswith ("text/html;" )
64
+ is_html = (
65
+ response ["Content-Type" ] == "text/html" or response ["Content-Type" ].startswith ("text/html;" ) if "Content-Type" in response else False
66
+ ) # noqa: E501 pylint: disable=line-too-long
61
67
if is_html :
62
68
response .content = re .sub (r'<a(.*href ?= ?[\'"]http.*)>' , r'<a rel="noopener noreferrer"\1>' , response .content .decode ())
63
69
return response
0 commit comments