Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions gradio/brotli_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,14 @@ async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
def _is_handler_excluded(self, scope: Scope) -> bool:
handler = scope.get("path", "")

return any(pattern.search(handler) for pattern in self.excluded_handlers)
# Short-circuit if no patterns to check
if not self.excluded_handlers:
return False

for pattern in self.excluded_handlers:
if pattern.search(handler):
return True
return False

# explicitly handle html, js, css, json via a whitelist. woff2 files are already compressed.
# we don't want to compress binary files as they do not benefit much and it can cause bugs
Expand Down Expand Up @@ -147,7 +154,9 @@ def __init__(
)
self.br_buffer = io.BytesIO()

async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None: # noqa
async def __call__(
self, scope: Scope, receive: Receive, send: Send
) -> None: # noqa
self.send = send
await self.app(scope, receive, self.send_with_brotli)

Expand Down