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