@@ -79,7 +79,7 @@ impl Accept {
79
79
// Handle empty strings, and wildcard directives.
80
80
if part. is_empty ( ) {
81
81
continue ;
82
- } else if part == "*" {
82
+ } else if part == "*/* " {
83
83
wildcard = true ;
84
84
continue ;
85
85
}
@@ -175,8 +175,8 @@ impl Header for Accept {
175
175
176
176
if self . wildcard {
177
177
match output. len ( ) {
178
- 0 => write ! ( output, "*" ) . unwrap ( ) ,
179
- _ => write ! ( output, ", *" ) . unwrap ( ) ,
178
+ 0 => write ! ( output, "*/* " ) . unwrap ( ) ,
179
+ _ => write ! ( output, ", */* " ) . unwrap ( ) ,
180
180
}
181
181
}
182
182
@@ -433,4 +433,28 @@ mod test {
433
433
assert ! ( content_type. is_ok( ) , "server is expected to return HTML content" ) ;
434
434
Ok ( ( ) )
435
435
}
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
+ }
436
460
}
0 commit comments