rama_http/layer/remove_header/
mod.rsuse crate::{header, HeaderMap, HeaderName};
pub mod request;
pub mod response;
#[doc(inline)]
pub use self::{
request::{RemoveRequestHeader, RemoveRequestHeaderLayer},
response::{RemoveResponseHeader, RemoveResponseHeaderLayer},
};
fn remove_headers_by_prefix(headers: &mut HeaderMap, prefix: &str) {
let keys: Vec<_> = headers
.keys()
.filter(|key| {
let s = key.as_str();
s.len() >= prefix.len() && s[..prefix.len()].eq_ignore_ascii_case(prefix)
})
.cloned()
.collect();
for key in keys {
headers.remove(key);
}
}
fn remove_headers_by_exact_name(headers: &mut HeaderMap, name: &HeaderName) {
headers.remove(name);
}
fn remove_hop_by_hop_request_headers(headers: &mut HeaderMap) {
for header in [
&header::CONNECTION,
&header::PROXY_CONNECTION,
&header::PROXY_AUTHORIZATION,
&header::TE,
&header::TRAILER,
&header::TRANSFER_ENCODING,
&header::UPGRADE,
&header::X_FORWARDED_FOR,
&header::X_FORWARDED_HOST,
&header::X_FORWARDED_PROTO,
&header::FORWARDED,
&header::VIA,
&header::CF_CONNECTING_IP,
&header::X_REAL_IP,
&header::X_CLIENT_IP,
&header::CLIENT_IP,
&header::TRUE_CLIENT_IP,
] {
headers.remove(header);
}
}
fn remove_hop_by_hop_response_headers(headers: &mut HeaderMap) {
for header in [
&header::CONNECTION,
&header::KEEP_ALIVE,
&header::PROXY_AUTHENTICATE,
&header::TRAILER,
&header::TRANSFER_ENCODING,
&header::UPGRADE,
] {
headers.remove(header);
}
}