@@ -91,10 +91,6 @@ def test_quality_level_default_zstd(self):
9191 """Tests COMPRESS_ZSTD_LEVEL default value is correctly set."""
9292 self .assertEqual (self .app .config ["COMPRESS_ZSTD_LEVEL" ], 3 )
9393
94- def test_mutate_weak_etags (self ):
95- """Tests COMPRESS_MUTATE_WEAK_ETAGS default value is correctly set."""
96- self .assertEqual (self .app .config ["COMPRESS_MUTATE_WEAK_ETAGS" ], True )
97-
9894 def test_evaluate_conditional_request (self ):
9995 """Tests COMPRESS_EVALUATE_CONDITIONAL_REQUEST default value
10096 is correctly set."""
@@ -625,30 +621,7 @@ def test_strong_etag_is_mutated_with_suffix_and_remains_strong(self):
625621 self .assertEqual (tag , "abc123:gzip" )
626622 self .assertEqual (int (r .headers ["Content-Length" ]), len (r .data ))
627623
628- def test_weak_etag_is_mutated_when_flag_true (self ):
629- client = self .app .test_client ()
630- r = client .get ("/weak/" , headers = [("Accept-Encoding" , "gzip" )])
631- self .assertEqual (r .status_code , 200 )
632- self .assertEqual (r .headers .get ("Content-Encoding" ), "gzip" )
633-
634- tag , is_weak = r .get_etag ()
635- self .assertTrue (is_weak )
636- self .assertEqual (tag , "abc123:gzip" )
637-
638- def test_strong_etag_is_mutated_when_flag_false (self ):
639- self .app .config ["COMPRESS_MUTATE_WEAK_ETAGS" ] = False
640- client = self .app .test_client ()
641- r = client .get ("/strong/" , headers = [("Accept-Encoding" , "gzip" )])
642- self .assertEqual (r .status_code , 200 )
643- self .assertEqual (r .headers .get ("Content-Encoding" ), "gzip" )
644-
645- tag , is_weak = r .get_etag ()
646- self .assertFalse (is_weak )
647- # :gzip suffix when flag is False
648- self .assertEqual (tag , "abc123:gzip" )
649-
650- def test_weak_etag_is_preserved_when_flag_false (self ):
651- self .app .config ["COMPRESS_MUTATE_WEAK_ETAGS" ] = False
624+ def test_weak_etag_is_preserved (self ):
652625 client = self .app .test_client ()
653626 r = client .get ("/weak/" , headers = [("Accept-Encoding" , "gzip" )])
654627 self .assertEqual (r .status_code , 200 )
@@ -678,17 +651,18 @@ def test_conditional_get_uses_strong_compressed_representation(self):
678651 def test_conditional_get_uses_weak_compressed_representation (self ):
679652 client = self .app .test_client ()
680653 r1 = client .get ("/weak/" , headers = [("Accept-Encoding" , "gzip" )])
654+ etag_header = r1 .headers ["ETag" ]
655+
681656 r2 = client .get (
682657 "/weak/" ,
683- headers = [
684- ("Accept-Encoding" , "gzip" ),
685- ("If-None-Match" , r1 .headers ["ETag" ]),
686- ],
658+ headers = [("Accept-Encoding" , "gzip" ), ("If-None-Match" , etag_header )],
687659 )
688- # This is the current behavior that breaks make_conditional
689- # weak etags due rewrite at after_request
690- # We would expect a 304 but it does not because of etag mismatch
691- self .assertEqual (r2 .status_code , 200 )
660+ # This is the new behaviour we would expect by not mutating
661+ # the weak etags at after_request
662+ self .assertEqual (r2 .status_code , 304 )
663+ self .assertEqual (r2 .headers .get ("ETag" ), etag_header )
664+ self .assertNotIn ("Content-Encoding" , r2 .headers )
665+ self .assertEqual (len (r2 .get_data ()), 0 )
692666
693667 def test_conditional_get_uses_strong_compressed_representation_evaluate_conditional (
694668 self ,
@@ -732,23 +706,6 @@ def test_conditional_get_uses_weak_compressed_representation_evaluate_conditiona
732706 self .assertNotIn ("Content-Encoding" , r2 .headers )
733707 self .assertEqual (len (r2 .get_data ()), 0 )
734708
735- def test_conditional_get_uses_weak_compressed_representation_no_mutate_etag (self ):
736- self .app .config ["COMPRESS_MUTATE_WEAK_ETAGS" ] = False
737- client = self .app .test_client ()
738- r1 = client .get ("/weak/" , headers = [("Accept-Encoding" , "gzip" )])
739- etag_header = r1 .headers ["ETag" ]
740-
741- r2 = client .get (
742- "/weak/" ,
743- headers = [("Accept-Encoding" , "gzip" ), ("If-None-Match" , etag_header )],
744- )
745- # This is the new behaviour we would expect by not mutating
746- # the weak etags at after_request
747- self .assertEqual (r2 .status_code , 304 )
748- self .assertEqual (r2 .headers .get ("ETag" ), etag_header )
749- self .assertNotIn ("Content-Encoding" , r2 .headers )
750- self .assertEqual (len (r2 .get_data ()), 0 )
751-
752709
753710if __name__ == "__main__" :
754711 unittest .main ()
0 commit comments