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
64
65
66
67
68
69
70
71
72
use {Header, HeaderName, HeaderValue};
#[derive(Clone, PartialEq, Eq, Debug)]
pub struct AccessControlAllowCredentials;
impl Header for AccessControlAllowCredentials {
fn name() -> &'static HeaderName {
&::http::header::ACCESS_CONTROL_ALLOW_CREDENTIALS
}
fn decode<'i, I: Iterator<Item = &'i HeaderValue>>(values: &mut I) -> Result<Self, ::Error> {
values
.next()
.and_then(|value| {
if value == "true" {
Some(AccessControlAllowCredentials)
} else {
None
}
})
.ok_or_else(::Error::invalid)
}
fn encode<E: Extend<::HeaderValue>>(&self, values: &mut E) {
values.extend(::std::iter::once(HeaderValue::from_static("true")));
}
}
#[cfg(test)]
mod tests {
use super::super::test_decode;
use super::*;
#[test]
fn allow_credentials_is_case_sensitive() {
let allow_header = test_decode::<AccessControlAllowCredentials>(&["true"]);
assert!(allow_header.is_some());
let allow_header = test_decode::<AccessControlAllowCredentials>(&["True"]);
assert!(allow_header.is_none());
}
}