refactor: reduce allocation on control headers checking
Diff
src/control_headers.rs | 6 +++---
src/handler.rs | 3 +--
2 files changed, 4 insertions(+), 5 deletions(-)
@@ -13,18 +13,18 @@ const CACHE_EXT_ONE_YEAR: [&str; 30] = [
];
pub fn append_headers(ext: &str, resp: &mut Response<Body>) {
pub fn append_headers(uri: &str, resp: &mut Response<Body>) {
let mut max_age = 60 * 60 * 24_u64;
if CACHE_EXT_ONE_HOUR
.iter()
.any(|x| ext.ends_with(&[".", *x].concat()))
.any(|x| uri.ends_with(&[".", *x].concat()))
{
max_age = 60 * 60;
} else if CACHE_EXT_ONE_YEAR
.iter()
.any(|x| ext.ends_with(&[".", *x].concat()))
.any(|x| uri.ends_with(&[".", *x].concat()))
{
max_age = 60 * 60 * 24 * 365;
}
@@ -74,8 +74,7 @@ impl RequestHandler {
}
let ext = uri_path.to_lowercase();
control_headers::append_headers(&ext, &mut resp);
control_headers::append_headers(&uri_path, &mut resp);
if self.opts.security_headers {