This commit is contained in:
Mateusz Gruszczyński committed 2026-10-08 09:42:10 +02:00
1 parent c24bc4279b
commit 3b3f0db377
84 files changed
+2686 -392

No files matched your search

+15
View File
@@ -126,6 +126,15 @@ impl Settings {
(1..=64).contains(&self.proactive_refresh_max_inflight),
"cache.proactive_refresh_max_inflight must be 1..64"
);
if let Some(value) = &self.via_header {
ensure!(
!value.is_empty()
&& value.len() <= 256
&& value.bytes().all(|byte| byte >= 0x20 && byte != 0x7f)
&& value.parse::<HeaderValue>().is_ok(),
"cache.via_header must be a valid 1..256 byte HTTP header value"
);
}
Ok(())
}
pub fn active_for(&self, route: Option<bool>) -> bool {
@@ -173,6 +182,12 @@ impl Settings {
if !self.enabled {
return;
}
if let Some(value) = &self.via_header {
headers.append(
http::header::VIA,
value.parse::<HeaderValue>().expect("validated cache Via header"),
);
}
if self.expose_status {
headers.insert("x-cache", HeaderValue::from_static(outcome));
}
+4
View File
@@ -173,6 +173,9 @@ pub struct Settings {
pub expose_hits: bool,
pub expose_cache_status: bool,
pub expose_resident_age: bool,
/// Optional response Via field value added by RustProxy cache handling.
/// `None` disables the header; the default is `Via: RustProxy`.
pub via_header: Option<String>,
}
impl Default for Settings {
fn default() -> Self {
@@ -240,6 +243,7 @@ impl Default for Settings {
expose_hits: false,
expose_cache_status: false,
expose_resident_age: false,
via_header: Some("RustProxy".into()),
}
}
}
+19
View File
@@ -126,6 +126,25 @@ mod dashboard_tests {
"RustProxy; fwd=bypass; detail=\"request_cookie\"; transformed"
);
}
#[test]
fn via_header_is_configurable_and_preserves_upstream_chain() {
let settings = Settings::default();
let mut headers = HeaderMap::new();
headers.append("via", HeaderValue::from_static("1.1 upstream"));
settings.annotate(&mut headers, "HIT", 1, 20);
let values: Vec<_> = headers
.get_all("via")
.iter()
.map(|value| value.to_str().unwrap())
.collect();
assert_eq!(values, vec!["1.1 upstream", "RustProxy"]);
let disabled = Settings { via_header: None, ..Settings::default() };
let mut headers = HeaderMap::new();
disabled.annotate(&mut headers, "MISS", 0, 0);
assert!(!headers.contains_key("via"));
}
#[test]
fn disabled_cache_strips_diagnostics_without_exposing_bypass_headers() {
let settings = Settings {