1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use mime::Mime;
use header::QualityItem;
#[derive(Clone, PartialEq, Debug)]
pub struct Accept(pub Vec<QualityItem<Mime>>);
impl_list_header!(Accept,
"Accept",
Vec<QualityItem<Mime>>);
#[cfg(test)]
mod tests {
use mime::*;
use header::{Header, Quality, QualityItem, qitem};
use super::Accept;
#[test]
fn test_parse_header_no_quality() {
let a: Accept = Header::parse_header([b"text/plain; charset=utf-8".to_vec()].as_slice()).unwrap();
let b = Accept(vec![
qitem(Mime(TopLevel::Text, SubLevel::Plain, vec![(Attr::Charset, Value::Utf8)])),
]);
assert_eq!(a, b);
}
#[test]
fn test_parse_header_with_quality() {
let a: Accept = Header::parse_header([b"text/plain; charset=utf-8; q=0.5".to_vec()].as_slice()).unwrap();
let b = Accept(vec![
QualityItem::new(Mime(TopLevel::Text, SubLevel::Plain, vec![(Attr::Charset, Value::Utf8)]), Quality(500)),
]);
assert_eq!(a, b);
}
}
bench_header!(bench, Accept, { vec![b"text/plain; q=0.5, text/html".to_vec()] });