From f70349470f022dac1a9a55a33714cda2f474a7b6 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Sun, 20 Sep 2020 01:06:23 -0700 Subject: [PATCH] Don't gzip large responses. --- frontends/etiquette_flask/backend/common.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/frontends/etiquette_flask/backend/common.py b/frontends/etiquette_flask/backend/common.py index 076edf6..946f3cd 100644 --- a/frontends/etiquette_flask/backend/common.py +++ b/frontends/etiquette_flask/backend/common.py @@ -72,6 +72,7 @@ def decorate_and_route(*route_args, **route_kwargs): site.route = decorate_and_route gzip_minimum_size = 500 +gzip_maximum_size = 5 * 2**20 gzip_level = 3 @site.after_request def after_request(response): @@ -85,6 +86,7 @@ def after_request(response): bail = bail or response.status_code < 200 bail = bail or response.status_code >= 300 bail = bail or response.direct_passthrough + bail = bail or int(response.headers.get('Content-Length', gzip_minimum_size)) > gzip_maximum_size bail = bail or len(response.get_data()) < gzip_minimum_size bail = bail or 'gzip' not in accept_encoding.lower() bail = bail or 'Content-Encoding' in response.headers