@@ -447,9 +447,9 @@ impl Accepts {
447
447
( true , true , true , false ) => Some ( "gzip, br, zstd" ) ,
448
448
( true , true , false , false ) => Some ( "gzip, br" ) ,
449
449
( true , false , true , true ) => Some ( "gzip, zstd, deflate" ) ,
450
- ( true , false , false , true ) => Some ( "gzip, zstd, deflate" ) ,
450
+ ( true , false , false , true ) => Some ( "gzip, deflate" ) ,
451
451
( false , true , true , true ) => Some ( "br, zstd, deflate" ) ,
452
- ( false , true , false , true ) => Some ( "br, zstd, deflate" ) ,
452
+ ( false , true , false , true ) => Some ( "br, deflate" ) ,
453
453
( true , false , true , false ) => Some ( "gzip, zstd" ) ,
454
454
( true , false , false , false ) => Some ( "gzip" ) ,
455
455
( false , true , true , false ) => Some ( "br, zstd" ) ,
@@ -524,3 +524,57 @@ impl Default for Accepts {
524
524
}
525
525
}
526
526
}
527
+
528
+ #[ cfg( test) ]
529
+ mod tests {
530
+ use super :: * ;
531
+
532
+ #[ test]
533
+ fn accepts_as_str ( ) {
534
+ fn format_accept_encoding ( accepts : & Accepts ) -> String {
535
+ let mut encodings = vec ! [ ] ;
536
+ if accepts. is_gzip ( ) {
537
+ encodings. push ( "gzip" ) ;
538
+ }
539
+ if accepts. is_brotli ( ) {
540
+ encodings. push ( "br" ) ;
541
+ }
542
+ if accepts. is_zstd ( ) {
543
+ encodings. push ( "zstd" ) ;
544
+ }
545
+ if accepts. is_deflate ( ) {
546
+ encodings. push ( "deflate" ) ;
547
+ }
548
+ encodings. join ( ", " )
549
+ }
550
+
551
+ let state = [ true , false ] ;
552
+ let mut permutations = Vec :: new ( ) ;
553
+
554
+ #[ allow( unused_variables) ]
555
+ for gzip in state {
556
+ for brotli in state {
557
+ for zstd in state {
558
+ for deflate in state {
559
+ permutations. push ( Accepts {
560
+ #[ cfg( feature = "gzip" ) ]
561
+ gzip,
562
+ #[ cfg( feature = "brotli" ) ]
563
+ brotli,
564
+ #[ cfg( feature = "zstd" ) ]
565
+ zstd,
566
+ #[ cfg( feature = "deflate" ) ]
567
+ deflate,
568
+ } ) ;
569
+ }
570
+ }
571
+ }
572
+ }
573
+
574
+ for accepts in permutations {
575
+ let expected = format_accept_encoding ( & accepts) ;
576
+ let got = accepts. as_str ( ) . unwrap_or ( "" ) ;
577
+ assert_eq ! ( got, expected. as_str( ) ) ;
578
+ }
579
+ }
580
+ }
0 commit comments