diff --git a/Cargo.toml b/Cargo.toml index da3f806..1c9d347 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,5 +42,7 @@ optimized = ["libwebp-sys?/sse41", "libwebp-sys?/avx2", "libwebp-sys?/neon"] qhash = ["blake3"] +prefix-path = [] + [profile.release] lto = true diff --git a/src/main.rs b/src/main.rs index 1b2264e..d255d45 100644 --- a/src/main.rs +++ b/src/main.rs @@ -112,6 +112,9 @@ fn is_header_allowed(header: &str) -> bool { !matches!( header, "host" + | "authorization" + | "cookie" + | "etag" | "content-length" | "set-cookie" | "alt-svc" diff --git a/src/utils.rs b/src/utils.rs index 8c415c3..3314be2 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -2,6 +2,16 @@ use qstring::QString; use reqwest::Url; use std::borrow::Cow; use std::collections::BTreeMap; +use std::env; + +#[cfg(feature = "prefix-path")] +{ + use once_cell::sync::Lazy; + static PREFIX_PATH: Lazy> = Lazy::new(|| match env::var("PREFIX_PATH") { + Ok(v) => Some(String::from(v)), + Err(e) => panic!("$PREFIX_PATH is not set ({})", e) + }); +} pub fn read_buf(buf: &[u8], pos: &mut usize) -> u8 { let byte = buf[*pos]; @@ -13,7 +23,6 @@ fn finalize_url(path: &str, query: BTreeMap) -> String { #[cfg(feature = "qhash")] { use std::collections::BTreeSet; - use std::env; let qhash = { let secret = env::var("HASH_SECRET"); @@ -46,12 +55,30 @@ fn finalize_url(path: &str, query: BTreeMap) -> String { if qhash.is_some() { let mut query = QString::new(query.into_iter().collect::>()); query.add_pair(("qhash", qhash.unwrap())); - return format!("{}?{}", path, query); + #[cfg(not(feature = "prefix-path"))] + { + return format!("{}?{}", path, query); + } + + + #[cfg(feature = "prefix-path")] + { + return format!("{}{}?{}", PREFIX_PATH.as_ref().unwrap().to_string(), path, query); + } } } let query = QString::new(query.into_iter().collect::>()); - format!("{}?{}", path, query) + #[cfg(not(feature = "prefix-path"))] + { + format!("{}?{}", path, query) + } + + + #[cfg(feature = "prefix-path")] + { + format!("{}{}?{}", PREFIX_PATH.as_ref().unwrap().to_string(), path, query) + } } pub fn localize_url(url: &str, host: &str) -> String {