sip_codec/headers/
allow.rs

1use std::fmt::{Display, Error, Formatter};
2
3use http::header::HeaderValue;
4use itertools::Itertools;
5
6use crate::headers::ParseHeader;
7
8#[derive(Debug, Clone, PartialEq, Eq, Hash)]
9pub struct Allow(pub Vec<String>);
10
11impl ParseHeader for Allow {
12	fn header_name() -> &'static [&'static str] {
13		&["allow"]
14	}
15
16	fn decode<'a>(headers: impl IntoIterator<Item = &'a HeaderValue>) -> Option<Self> {
17		headers
18			.into_iter()
19			.next()
20			.and_then(|header| header.to_str().ok())
21			.map(|value| value.split(',').map(|method| method.trim().to_string()))
22			.map(Iterator::collect)
23			.map(Self)
24	}
25}
26
27impl Display for Allow {
28	fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
29		write!(f, "{}", self.0.iter().join(", "))
30	}
31}