@@ -53,7 +53,7 @@ const FALLBACK_FAVICON_ICO: &[u8] = include_bytes!("../spin-favicon.ico");
5353const BUFFER_SIZE : usize = 64 * 1024 ;
5454const DEFLATE_LEVEL : flate2:: Compression = flate2:: Compression :: fast ( ) ;
5555
56- #[ derive( PartialEq ) ]
56+ #[ derive( PartialEq , Debug ) ]
5757struct ContentEncoding {
5858 // We limit expressed encodings to ones that we support
5959 encoding : SupportedEncoding ,
@@ -179,25 +179,18 @@ impl SupportedEncoding {
179179 . iter ( )
180180 . filter ( |( k, _) | HeaderName :: from_bytes ( k. as_bytes ( ) ) . ok ( ) == Some ( ACCEPT_ENCODING ) )
181181 . flat_map ( |( _, v) | {
182- str:: from_utf8 ( v) . ok ( ) . map ( |v| {
183- v. split ( ',' )
184- . map ( |v| ContentEncoding :: from_str ( v) . ok ( ) )
185- . filter ( |v| match v {
186- Some ( y) => match y. encoding {
187- // Filter out "None" values to ensure some compression is
188- // preferred. This is mostly to be defensive to types we don't
189- // understand as we only parse encodings we support.
190- // It's probably subpar if somebody actually _doesn't_ want
191- // compression but supports it anyway.
192- SupportedEncoding :: None => false ,
193- _ => true ,
194- } ,
195- None => false ,
196- } )
197- . flatten ( )
182+ str:: from_utf8 ( v) . ok ( ) . into_iter ( ) . flat_map ( |v| {
183+ v. split ( ',' ) . filter_map ( |v| {
184+ let e = ContentEncoding :: from_str ( v) . ok ( ) ?;
185+ // Filter out "None" values to ensure some compression is
186+ // preferred. This is mostly to be defensive to types we don't
187+ // understand as we only parse encodings we support.
188+ // It's probably subpar if somebody actually _doesn't_ want
189+ // compression but supports it anyway.
190+ ( e. encoding != SupportedEncoding :: None ) . then_some ( e)
191+ } )
198192 } )
199193 } )
200- . flatten ( )
201194 . collect ( ) ;
202195
203196 accepted_encodings. sort_by ( |a, b| b. partial_cmp ( a) . unwrap_or ( Ordering :: Equal ) ) ;
0 commit comments