use super::headers::Header; use anyhow::Result; use std::fmt::Display; #[derive(Debug)] pub struct HeaderMap(pub Vec<(String, String)>); impl HeaderMap { pub fn new() -> Self { Self(vec![]) } pub fn add(mut self, h: H) -> Self { self.0.push((H::NAME.to_string(), format!("{h}"))); self } pub fn get(&self) -> Option> { self.0 .iter() .find(|(k, _)| k == H::NAME) .map(|(_, v)| H::from_str(v)) } pub fn insert_raw(&mut self, key: String, value: String) { self.0.push((key, value)) } } impl Display for HeaderMap { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { for (k, v) in &self.0 { write!(f, "{k}: {v}\r\n")?; } Ok(()) } }