Skip to content

Commit ed7907f

Browse files
committed
Make COMPRESS_EVALUATE_CONDITIONAL_REQUEST default to True
1 parent 9e63fa8 commit ed7907f

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,4 @@ Within your Flask application's settings you can provide the following settings
144144
| `COMPRESS_REGISTER` | Specifies if compression should be automatically registered. | `True` |
145145
| `COMPRESS_ALGORITHM` | Supported compression algorithms. | `['zstd', 'br', 'gzip', 'deflate']` |
146146
| `COMPRESS_STREAMS` | Compress content streams. | `True` |
147-
| `COMPRESS_EVALUATE_CONDITIONAL_REQUEST` | Compress evaluates conditional requests. | `False` |
147+
| `COMPRESS_EVALUATE_CONDITIONAL_REQUEST` | Compress evaluates conditional requests. | `True` |

flask_compress/flask_compress.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def init_app(self, app):
165165
("COMPRESS_CACHE_BACKEND", None),
166166
("COMPRESS_REGISTER", True),
167167
("COMPRESS_STREAMS", True),
168-
("COMPRESS_EVALUATE_CONDITIONAL_REQUEST", False),
168+
("COMPRESS_EVALUATE_CONDITIONAL_REQUEST", True),
169169
("COMPRESS_ALGORITHM", ["zstd", "br", "gzip", "deflate"]),
170170
]
171171

tests/test_flask_compress.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def test_evaluate_conditional_request(self):
9595
"""Tests COMPRESS_EVALUATE_CONDITIONAL_REQUEST default value
9696
is correctly set."""
9797
self.assertEqual(
98-
self.app.config["COMPRESS_EVALUATE_CONDITIONAL_REQUEST"], False
98+
self.app.config["COMPRESS_EVALUATE_CONDITIONAL_REQUEST"], True
9999
)
100100

101101

@@ -633,6 +633,7 @@ def test_weak_etag_is_preserved(self):
633633
self.assertEqual(tag, "abc123")
634634

635635
def test_conditional_get_uses_strong_compressed_representation(self):
636+
self.app.config["COMPRESS_EVALUATE_CONDITIONAL_REQUEST"] = False
636637
client = self.app.test_client()
637638
r1 = client.get("/strong/", headers=[("Accept-Encoding", "gzip")])
638639

@@ -643,12 +644,13 @@ def test_conditional_get_uses_strong_compressed_representation(self):
643644
("If-None-Match", r1.headers["ETag"]),
644645
],
645646
)
646-
# This is the current behavior that breaks make_conditional
647+
# This is the old behavior that broke make_conditional
647648
# strong etags due rewrite at after_request
648649
# We would expect a 304 but it does not because of etag mismatch
649650
self.assertEqual(r2.status_code, 200)
650651

651652
def test_conditional_get_uses_weak_compressed_representation(self):
653+
self.app.config["COMPRESS_EVALUATE_CONDITIONAL_REQUEST"] = False
652654
client = self.app.test_client()
653655
r1 = client.get("/weak/", headers=[("Accept-Encoding", "gzip")])
654656
etag_header = r1.headers["ETag"]
@@ -657,7 +659,7 @@ def test_conditional_get_uses_weak_compressed_representation(self):
657659
"/weak/",
658660
headers=[("Accept-Encoding", "gzip"), ("If-None-Match", etag_header)],
659661
)
660-
# This is the new behaviour we would expect by not mutating
662+
# This is the behaviour we expect by not mutating
661663
# the weak etags at after_request
662664
self.assertEqual(r2.status_code, 304)
663665
self.assertEqual(r2.headers.get("ETag"), etag_header)
@@ -667,7 +669,6 @@ def test_conditional_get_uses_weak_compressed_representation(self):
667669
def test_conditional_get_uses_strong_compressed_representation_evaluate_conditional(
668670
self,
669671
):
670-
self.app.config["COMPRESS_EVALUATE_CONDITIONAL_REQUEST"] = True
671672
client = self.app.test_client()
672673
r1 = client.get(
673674
"/strong-compress-conditional/", headers=[("Accept-Encoding", "gzip")]
@@ -678,7 +679,7 @@ def test_conditional_get_uses_strong_compressed_representation_evaluate_conditio
678679
"/strong-compress-conditional/",
679680
headers=[("Accept-Encoding", "gzip"), ("If-None-Match", etag_header)],
680681
)
681-
# This is the new behaviour we would expect after evaluating
682+
# This is the behaviour we would expect after evaluating
682683
# flask make_conditional at after_request
683684
self.assertEqual(r2.status_code, 304)
684685
self.assertEqual(r2.headers.get("ETag"), etag_header)
@@ -688,7 +689,6 @@ def test_conditional_get_uses_strong_compressed_representation_evaluate_conditio
688689
def test_conditional_get_uses_weak_compressed_representation_evaluate_conditional(
689690
self,
690691
):
691-
self.app.config["COMPRESS_EVALUATE_CONDITIONAL_REQUEST"] = True
692692
client = self.app.test_client()
693693
r1 = client.get(
694694
"/weak-compress-conditional/", headers=[("Accept-Encoding", "gzip")]
@@ -699,7 +699,7 @@ def test_conditional_get_uses_weak_compressed_representation_evaluate_conditiona
699699
"/weak-compress-conditional/",
700700
headers=[("Accept-Encoding", "gzip"), ("If-None-Match", etag_header)],
701701
)
702-
# This is the new behaviour we would expect after evaluating
702+
# This is the behaviour we would expect after evaluating
703703
# flask make_conditional at after_request
704704
self.assertEqual(r2.status_code, 304)
705705
self.assertEqual(r2.headers.get("ETag"), etag_header)

0 commit comments

Comments
 (0)