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