Skip to content

Commit 1559500

Browse files
authored
Avoid installing middleware if Content-Encoding is set at all (#1560)
The previous check for "gzip" ignored the possibility of other `Content-Encoding` values, such as Brotli’s ``br``, which the middleware could also not touch. Instead, do not attempt to alter the content for *any* `Content-Encoding`. I tested by installing django-brotli in the example app below the toolbar middleware and hitting it with: ``` curl http://localhost:8000/ -H 'Accept-Encoding: br' ``` Without the change, it would crash with: ``` File "/.../debug_toolbar/middleware.py", line 87, in __call__ content = response.content.decode(response.charset) UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc7 in position 1: invalid continuation byte ``` After, it is fixed.
1 parent afc5dfc commit 1559500

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

debug_toolbar/middleware.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def __call__(self, request):
7878
content_type = response.get("Content-Type", "").split(";")[0]
7979
if (
8080
getattr(response, "streaming", False)
81-
or "gzip" in content_encoding
81+
or content_encoding != ""
8282
or content_type not in _HTML_TYPES
8383
):
8484
return response

0 commit comments

Comments
 (0)