@@ -79,7 +79,7 @@ impl Accept {
7979 // Handle empty strings, and wildcard directives.
8080 if part. is_empty ( ) {
8181 continue ;
82- } else if part == "*" {
82+ } else if part == "*/* " {
8383 wildcard = true ;
8484 continue ;
8585 }
@@ -175,8 +175,8 @@ impl Header for Accept {
175175
176176 if self . wildcard {
177177 match output. len ( ) {
178- 0 => write ! ( output, "*" ) . unwrap ( ) ,
179- _ => write ! ( output, ", *" ) . unwrap ( ) ,
178+ 0 => write ! ( output, "*/* " ) . unwrap ( ) ,
179+ _ => write ! ( output, ", */* " ) . unwrap ( ) ,
180180 }
181181 }
182182
@@ -433,4 +433,28 @@ mod test {
433433 assert ! ( content_type. is_ok( ) , "server is expected to return HTML content" ) ;
434434 Ok ( ( ) )
435435 }
436+
437+ #[ test]
438+ fn parse ( ) -> crate :: Result < ( ) > {
439+ let mut headers = Headers :: new ( ) ;
440+ headers. insert ( "Accept" , "application/json; q=0.8,*/*" ) ?;
441+ let accept = Accept :: from_headers ( headers) ?. unwrap ( ) ;
442+
443+ assert ! ( accept. wildcard( ) ) ;
444+ assert_eq ! (
445+ accept. into_iter( ) . collect:: <Vec <_>>( ) ,
446+ vec![ MediaTypeProposal :: new( mime:: JSON , Some ( 0.8 ) ) ?]
447+ ) ;
448+ Ok ( ( ) )
449+ }
450+
451+ #[ test]
452+ fn serialize ( ) -> crate :: Result < ( ) > {
453+ let mut accept = Accept :: new ( ) ;
454+ accept. push ( MediaTypeProposal :: new ( mime:: JSON , Some ( 0.8 ) ) ?) ;
455+ accept. set_wildcard ( true ) ;
456+
457+ assert_eq ! ( accept. header_value( ) . as_str( ) , "application/json;q=0.800, */*" ) ;
458+ Ok ( ( ) )
459+ }
436460}
0 commit comments