sip_codec/headers/
user_agent.rs1use std::fmt::{Display, Error, Formatter};
2
3use http::header::HeaderValue;
4
5use crate::headers::ParseHeader;
6
7#[derive(Debug, Clone, PartialEq, Eq, Hash)]
8pub struct UserAgent(pub String);
9
10impl ParseHeader for UserAgent {
11 fn header_name() -> &'static [&'static str] {
12 &["user-agent"]
13 }
14
15 fn decode<'a>(headers: impl IntoIterator<Item = &'a HeaderValue>) -> Option<Self> {
16 headers
17 .into_iter()
18 .next()
19 .and_then(|header| header.to_str().ok())
20 .map(|value| value.into())
21 .map(Self)
22 }
23}
24
25impl Display for UserAgent {
26 fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
27 write!(f, "{}", self.0)
28 }
29}