Skip to content

Commit e6ae9d0

Browse files
authored
Fix the test for basic app (#221)
1. Update the test app If I understand correctly, the debug toolbar will only be enabled if `app.debug` is `True`. So I added the `DEBUG=True` to the test app. Related code: https://github.com/pallets-eco/flask-debugtoolbar/blob/2b8bf9cc449a95f442b99dfdfb6147fa1ae2230a/src/flask_debugtoolbar/__init__.py#L114 2. Update the `src/flask_debugtoolbar/__init__.py` Fix the two if statements to prevent the following errors: ``` > if 'gzip' in response.headers.get('Content-Encoding'): E TypeError: argument of type 'NoneType' is not iterable ``` Since the `response.headers.get('Content-Encoding')` could be None. With this PR, all the tests will be passed. The failed style checker will be fixed in #219
1 parent 62ce443 commit e6ae9d0

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/flask_debugtoolbar/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,8 @@ def process_response(self, response):
230230
response.headers['content-type'].startswith('text/html')):
231231
return response
232232

233-
if 'gzip' in response.headers.get('Content-Encoding'):
233+
content_encoding = response.headers.get('Content-Encoding')
234+
if content_encoding and 'gzip' in content_encoding:
234235
response_html = gzip_decompress(response.data).decode()
235236
else:
236237
response_html = response.get_data(as_text=True)
@@ -258,7 +259,7 @@ def process_response(self, response):
258259

259260
content = ''.join((before, toolbar_html, after))
260261
content = content.encode('utf-8')
261-
if 'gzip' in response.headers.get('Content-Encoding'):
262+
if content_encoding and 'gzip' in content_encoding:
262263
content = gzip_compress(content)
263264
response.response = [content]
264265
response.content_length = len(content)

test/basic_app.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from flask_debugtoolbar import DebugToolbarExtension
55

66
app = Flask('basic_app')
7+
app.config['DEBUG'] = True
78
app.config['SECRET_KEY'] = 'abc123'
89
app.config['SQLALCHEMY_RECORD_QUERIES'] = True
910
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:'

0 commit comments

Comments
 (0)