actix_web/http/header/
allow.rs

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