@@ -484,9 +484,9 @@ impl Accepts {
484
484
( true , true , true , false ) => Some ( "gzip, br, zstd" ) ,
485
485
( true , true , false , false ) => Some ( "gzip, br" ) ,
486
486
( true , false , true , true ) => Some ( "gzip, zstd, deflate" ) ,
487
- ( true , false , false , true ) => Some ( "gzip, zstd, deflate" ) ,
487
+ ( true , false , false , true ) => Some ( "gzip, deflate" ) ,
488
488
( false , true , true , true ) => Some ( "br, zstd, deflate" ) ,
489
- ( false , true , false , true ) => Some ( "br, zstd, deflate" ) ,
489
+ ( false , true , false , true ) => Some ( "br, deflate" ) ,
490
490
( true , false , true , false ) => Some ( "gzip, zstd" ) ,
491
491
( true , false , false , false ) => Some ( "gzip" ) ,
492
492
( false , true , true , false ) => Some ( "br, zstd" ) ,
@@ -561,3 +561,57 @@ impl Default for Accepts {
561
561
}
562
562
}
563
563
}
564
+
565
+ #[ cfg( test) ]
566
+ mod tests {
567
+ use super :: * ;
568
+
569
+ #[ test]
570
+ fn accepts_as_str ( ) {
571
+ fn format_accept_encoding ( accepts : & Accepts ) -> String {
572
+ let mut encodings = vec ! [ ] ;
573
+ if accepts. is_gzip ( ) {
574
+ encodings. push ( "gzip" ) ;
575
+ }
576
+ if accepts. is_brotli ( ) {
577
+ encodings. push ( "br" ) ;
578
+ }
579
+ if accepts. is_zstd ( ) {
580
+ encodings. push ( "zstd" ) ;
581
+ }
582
+ if accepts. is_deflate ( ) {
583
+ encodings. push ( "deflate" ) ;
584
+ }
585
+ encodings. join ( ", " )
586
+ }
587
+
588
+ let state = [ true , false ] ;
589
+ let mut permutations = Vec :: new ( ) ;
590
+
591
+ #[ allow( unused_variables) ]
592
+ for gzip in state {
593
+ for brotli in state {
594
+ for zstd in state {
595
+ for deflate in state {
596
+ permutations. push ( Accepts {
597
+ #[ cfg( feature = "gzip" ) ]
598
+ gzip,
599
+ #[ cfg( feature = "brotli" ) ]
600
+ brotli,
601
+ #[ cfg( feature = "zstd" ) ]
602
+ zstd,
603
+ #[ cfg( feature = "deflate" ) ]
604
+ deflate,
605
+ } ) ;
606
+ }
607
+ }
608
+ }
609
+ }
610
+
611
+ for accepts in permutations {
612
+ let expected = format_accept_encoding ( & accepts) ;
613
+ let got = accepts. as_str ( ) . unwrap_or ( "" ) ;
614
+ assert_eq ! ( got, expected. as_str( ) ) ;
615
+ }
616
+ }
617
+ }
0 commit comments