cogo_http/header/common/
allow.rs

1use crate::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    /// ```plain
13    /// Allow = #method
14    /// ```
15    ///
16    /// # Example values
17    /// * `GET, HEAD, PUT`
18    /// * `OPTIONS, GET, PUT, POST, DELETE, HEAD, TRACE, CONNECT, PATCH, fOObAr`
19    /// * ``
20    ///
21    /// # Examples
22    /// ```
23    /// use cogo_http::header::{Headers, Allow};
24    /// use cogo_http::method::Method;
25    ///
26    /// let mut headers = Headers::new();
27    /// headers.set(
28    ///     Allow(vec![Method::Get])
29    /// );
30    /// ```
31    /// ```
32    /// use cogo_http::header::{Headers, Allow};
33    /// use cogo_http::method::Method;
34    ///
35    /// let mut headers = Headers::new();
36    /// headers.set(
37    ///     Allow(vec![
38    ///         Method::Get,
39    ///         Method::Post,
40    ///         Method::Patch,
41    ///         Method::Extension("COPY".to_owned()),
42    ///     ])
43    /// );
44    /// ```
45    (Allow, "Allow") => (Method)*
46
47    test_allow {
48        // From the RFC
49        test_header!(
50            test1,
51            vec![b"GET, HEAD, PUT"],
52            Some(HeaderField(vec![Method::Get, Method::Head, Method::Put])));
53        // Own tests
54        test_header!(
55            test2,
56            vec![b"OPTIONS, GET, PUT, POST, DELETE, HEAD, TRACE, CONNECT, PATCH, fOObAr"],
57            Some(HeaderField(vec![
58                Method::Options,
59                Method::Get,
60                Method::Put,
61                Method::Post,
62                Method::Delete,
63                Method::Head,
64                Method::Trace,
65                Method::Connect,
66                Method::Patch,
67                Method::Extension("fOObAr".to_owned())])));
68        test_header!(
69            test3,
70            vec![b""],
71            Some(HeaderField(Vec::<Method>::new())));
72    }
73}
74
75bench_header!(bench,
76    Allow, { vec![b"OPTIONS,GET,PUT,POST,DELETE,HEAD,TRACE,CONNECT,PATCH,fOObAr".to_vec()] });