headers_ext/common/
access_control_request_method.rs1use http::Method;
2use ::{Header, HeaderName, HeaderValue};
3
4#[derive(Clone, Debug, PartialEq, Eq, Hash)]
29pub struct AccessControlRequestMethod(Method);
30
31impl Header for AccessControlRequestMethod {
32 const NAME: &'static HeaderName = &::http::header::ACCESS_CONTROL_REQUEST_METHOD;
33
34 fn decode<'i, I: Iterator<Item = &'i HeaderValue>>(values: &mut I) -> Result<Self, ::Error> {
35 values.next()
36 .and_then(|value| {
37 Method::from_bytes(value.as_bytes()).ok()
38 })
39 .map(AccessControlRequestMethod)
40 .ok_or_else(::Error::invalid)
41 }
42
43 fn encode<E: Extend<::HeaderValue>>(&self, values: &mut E) {
44 let s = match self.0 {
46 Method::GET => "GET",
47 Method::POST => "POST",
48 Method::PUT => "PUT",
49 Method::DELETE => "DELETE",
50 _ => {
51 let val = HeaderValue::from_str(self.0.as_ref())
52 .expect("Methods are also valid HeaderValues");
53 values.extend(::std::iter::once(val));
54 return;
55 }
56 };
57
58 values.extend(::std::iter::once(HeaderValue::from_static(s)));
59 }
60}
61
62impl From<Method> for AccessControlRequestMethod {
63 fn from(method: Method) -> AccessControlRequestMethod {
64 AccessControlRequestMethod(method)
65 }
66}
67