hyperx/header/common/
allow.rs

1use method::Method;
2
3header! {
4    /// `Allow` header, defined in [RFC7231](http://tools.ietf.org/html/rfc7231#section-7.4.1)
5    ///
6    /// The `Allow` header field lists the set of methods advertised as
7    /// supported by the target resource.  The purpose of this field is
8    /// strictly to inform the recipient of valid request methods associated
9    /// with the resource.
10    ///
11    /// # ABNF
12    ///
13    /// ```text
14    /// Allow = #method
15    /// ```
16    ///
17    /// # Example values
18    /// * `GET, HEAD, PUT`
19    /// * `OPTIONS, GET, PUT, POST, DELETE, HEAD, TRACE, CONNECT, PATCH, fOObAr`
20    /// * ``
21    ///
22    /// # Examples
23    ///
24    /// ```
25    /// # extern crate http;
26    /// use hyperx::header::{Allow, TypedHeaders};
27    /// use hyperx::Method;
28    ///
29    /// let mut headers = http::HeaderMap::new();
30    /// headers.encode(
31    ///     &Allow(vec![Method::Get])
32    /// );
33    /// ```
34    ///
35    /// ```
36    /// # extern crate http;
37    /// use hyperx::header::{Allow, TypedHeaders};
38    /// use hyperx::Method;
39    ///
40    /// let mut headers = http::HeaderMap::new();
41    /// headers.encode(
42    ///     &Allow(vec![
43    ///         Method::Get,
44    ///         Method::Post,
45    ///         Method::Patch,
46    ///         Method::Extension("COPY".to_owned()),
47    ///     ])
48    /// );
49    /// ```
50    (Allow, "Allow") => (Method)*
51
52    test_allow {
53        // From the RFC
54        test_header!(
55            test1,
56            vec![b"GET, HEAD, PUT"],
57            Some(HeaderField(vec![Method::Get, Method::Head, Method::Put])));
58        // Own tests
59        test_header!(
60            test2,
61            vec![b"OPTIONS, GET, PUT, POST, DELETE, HEAD, TRACE, CONNECT, PATCH, fOObAr"],
62            Some(HeaderField(vec![
63                Method::Options,
64                Method::Get,
65                Method::Put,
66                Method::Post,
67                Method::Delete,
68                Method::Head,
69                Method::Trace,
70                Method::Connect,
71                Method::Patch,
72                Method::Extension("fOObAr".to_owned())])));
73        test_header!(
74            test3,
75            vec![b""],
76            Some(HeaderField(Vec::<Method>::new())));
77    }
78}
79
80bench_header!(bench,
81    Allow, { vec![b"OPTIONS,GET,PUT,POST,DELETE,HEAD,TRACE,CONNECT,PATCH,fOObAr".to_vec()] });
82
83standard_header!(Allow, ALLOW);