Coverage Report

Created: 2026-03-11 07:34

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/headers-0.4.1/src/common/allow.rs
Line
Count
Source
1
use std::iter::FromIterator;
2
3
use http::{HeaderValue, Method};
4
5
use crate::util::FlatCsv;
6
7
/// `Allow` header, defined in [RFC7231](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
///
16
/// ```text
17
/// Allow = #method
18
/// ```
19
///
20
/// # Example values
21
/// * `GET, HEAD, PUT`
22
/// * `OPTIONS, GET, PUT, POST, DELETE, HEAD, TRACE, CONNECT, PATCH, fOObAr`
23
/// * ``
24
///
25
/// # Examples
26
///
27
/// ```
28
/// extern crate http;
29
/// use headers::Allow;
30
/// use http::Method;
31
///
32
/// let allow = vec![Method::GET, Method::POST]
33
///     .into_iter()
34
///     .collect::<Allow>();
35
/// ```
36
#[derive(Clone, Debug, PartialEq)]
37
pub struct Allow(FlatCsv);
38
39
derive_header! {
40
    Allow(_),
41
    name: ALLOW
42
}
43
44
impl Allow {
45
    /// Returns an iterator over `Method`s contained within.
46
0
    pub fn iter(&self) -> impl Iterator<Item = Method> + '_ {
47
0
        self.0.iter().filter_map(|s| s.parse().ok())
48
0
    }
49
}
50
51
impl FromIterator<Method> for Allow {
52
0
    fn from_iter<I>(iter: I) -> Self
53
0
    where
54
0
        I: IntoIterator<Item = Method>,
55
    {
56
0
        let flat = iter
57
0
            .into_iter()
58
0
            .map(|method| {
59
0
                method
60
0
                    .as_str()
61
0
                    .parse::<HeaderValue>()
62
0
                    .expect("Method is a valid HeaderValue")
63
0
            })
64
0
            .collect();
65
0
        Allow(flat)
66
0
    }
67
}