use std::collections::BTreeSet;
use crate::constants::DEFAULT_SENSITIVE_HEADER_NAMES;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SensitiveHttpHeaders {
headers: BTreeSet<String>,
}
impl SensitiveHttpHeaders {
pub fn new() -> Self {
Self {
headers: BTreeSet::new(),
}
}
pub fn contains(&self, header_name: &str) -> bool {
self.headers.contains(&header_name.to_lowercase())
}
pub fn insert(&mut self, header_name: &str) {
let value = header_name.trim().to_lowercase();
if !value.is_empty() {
self.headers.insert(value);
}
}
pub fn extend<I, S>(&mut self, headers: I)
where
I: IntoIterator<Item = S>,
S: AsRef<str>,
{
for header in headers {
self.insert(header.as_ref());
}
}
pub fn clear(&mut self) {
self.headers.clear();
}
pub fn len(&self) -> usize {
self.headers.len()
}
pub fn is_empty(&self) -> bool {
self.headers.is_empty()
}
pub fn iter(&self) -> impl Iterator<Item = &str> {
self.headers.iter().map(String::as_str)
}
}
impl Default for SensitiveHttpHeaders {
fn default() -> Self {
let mut result = SensitiveHttpHeaders::new();
result.extend(DEFAULT_SENSITIVE_HEADER_NAMES);
result
}
}