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
use http::Method;
use ::{Header, HeaderName, HeaderValue};
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct AccessControlRequestMethod(Method);
impl Header for AccessControlRequestMethod {
const NAME: &'static HeaderName = &::http::header::ACCESS_CONTROL_REQUEST_METHOD;
fn decode(values: &mut ::Values) -> Option<Self> {
values.next()
.and_then(|value| {
Method::from_bytes(value.as_bytes()).ok()
})
.map(AccessControlRequestMethod)
}
fn encode(&self, values: &mut ::ToValues) {
let s = match self.0 {
Method::GET => "GET",
Method::POST => "POST",
Method::PUT => "PUT",
Method::DELETE => "DELETE",
_ => {
let val = HeaderValue::from_str(self.0.as_ref())
.expect("Methods are also valid HeaderValues");
values.append(val);
return;
}
};
values.append(HeaderValue::from_static(s))
}
}
impl From<Method> for AccessControlRequestMethod {
fn from(method: Method) -> AccessControlRequestMethod {
AccessControlRequestMethod(method)
}
}