use std::collections::HashMap;
#[derive(Clone, Debug, Default, Eq, PartialEq)]
pub struct Headers {
values: HashMap<String, String>,
}
impl Headers {
#[must_use]
pub fn new() -> Self {
Self::default()
}
pub fn insert(&mut self, name: impl AsRef<str>, value: impl Into<String>) {
self.values
.insert(name.as_ref().to_ascii_lowercase(), value.into());
}
#[must_use]
pub fn get(&self, name: &str) -> Option<&str> {
self.values
.get(&name.to_ascii_lowercase())
.map(String::as_str)
}
#[must_use]
pub fn len(&self) -> usize {
self.values.len()
}
#[must_use]
pub fn is_empty(&self) -> bool {
self.values.is_empty()
}
pub fn iter(&self) -> impl Iterator<Item = (&str, &str)> {
self.values.iter().map(|(k, v)| (k.as_str(), v.as_str()))
}
}