Skip to content

Commit 767c94e

Browse files
committed
Fixes Accept wildcard
It is "*/*" according to https://tools.ietf.org/html/rfc7231#section-5.3.2
1 parent dab0f62 commit 767c94e

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

src/content/accept.rs

+30-3
Original file line numberDiff line numberDiff line change
@@ -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
}
@@ -177,8 +177,8 @@ impl Header for Accept {
177177

178178
if self.wildcard {
179179
match output.len() {
180-
0 => write!(output, "*").unwrap(),
181-
_ => write!(output, ", *").unwrap(),
180+
0 => write!(output, "*/*").unwrap(),
181+
_ => write!(output, ", */*").unwrap(),
182182
}
183183
}
184184

@@ -420,4 +420,31 @@ mod test {
420420
assert_eq!(accept.negotiate(&[mime::XML])?, mime::XML);
421421
Ok(())
422422
}
423+
424+
#[test]
425+
fn parse() -> crate::Result<()> {
426+
let mut headers = Headers::new();
427+
headers.insert("Accept", "application/json; q=0.8,*/*");
428+
let accept = Accept::from_headers(headers)?.unwrap();
429+
430+
assert!(accept.wildcard());
431+
assert_eq!(
432+
accept.into_iter().collect::<Vec<_>>(),
433+
vec![MediaTypeProposal::new(mime::JSON, Some(0.8))?]
434+
);
435+
Ok(())
436+
}
437+
438+
#[test]
439+
fn serialize() -> crate::Result<()> {
440+
let mut accept = Accept::new();
441+
accept.push(MediaTypeProposal::new(mime::JSON, Some(0.8))?);
442+
accept.set_wildcard(true);
443+
444+
assert_eq!(
445+
accept.header_value().as_str(),
446+
"application/json;q=0.800, */*"
447+
);
448+
Ok(())
449+
}
423450
}

0 commit comments

Comments
 (0)