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
60
61
62
63
use http::header::ACCEPT;
use mime::Mime;
use QualityItem;
header! {
/// `Accept` header, defined in [RFC7231](http://tools.ietf.org/html/rfc7231#section-5.3.2)
///
/// The `Accept` header field can be used by user agents to specify
/// response media types that are acceptable. Accept header fields can
/// be used to indicate that the request is specifically limited to a
/// small set of desired types, as in the case of a request for an
/// in-line image
///
/// # ABNF
///
/// ```text
/// Accept = #( media-range [ accept-params ] )
///
/// media-range = ( "*/*"
/// / ( type "/" "*" )
/// / ( type "/" subtype )
/// ) *( OWS ";" OWS parameter )
/// accept-params = weight *( accept-ext )
/// accept-ext = OWS ";" OWS token [ "=" ( token / quoted-string ) ]
/// ```
///
/// # Example values
/// * `audio/*; q=0.2, audio/basic`
/// * `text/plain; q=0.5, text/html, text/x-dvi; q=0.8, text/x-c`
(Accept, ACCEPT) => (QualityItem<Mime>)*
}
#[cfg(test)]
mod test {
use {util, Quality, QualityItem};
use super::*;
#[test]
fn rfc1() {
util::test_round_trip(
&Accept(vec![
QualityItem::new("audio/*".parse().unwrap(), Quality::from_u16(200)),
QualityItem::new("audio/basic".parse().unwrap(), Quality::from_u16(1000)),
]),
&["audio/*; q=0.2, audio/basic"],
);
}
#[test]
fn rfc2() {
util::test_round_trip(
&Accept(vec![
QualityItem::new("text/plain".parse().unwrap(), Quality::from_u16(500)),
QualityItem::new("text/html".parse().unwrap(), Quality::from_u16(1000)),
QualityItem::new("text/x-dvi".parse().unwrap(), Quality::from_u16(800)),
QualityItem::new("text/x-c".parse().unwrap(), Quality::from_u16(1000)),
]),
&["text/plain; q=0.5, text/html, text/x-dvi; q=0.8, text/x-c"],
);
}
}