This commit is contained in:
Mateusz Gruszczyński committed 2026-10-25 10:15:26 +01:00
1 parent b3dfd570b5
commit a4042d6439
16 files changed
+362 -55

No files matched your search

+79 -9
View File
@@ -171,7 +171,7 @@ impl Settings {
.any(|item| item.eq_ignore_ascii_case(extension))
}
pub fn annotate(&self, headers: &mut HeaderMap, outcome: &'static str, hits: u64, ttl: u64) {
self.annotate_internal(headers, outcome, hits, ttl, None, false);
self.annotate_internal(headers, outcome, hits, ttl as i64, None, false, None);
}
pub fn annotate_reason(
@@ -182,7 +182,15 @@ impl Settings {
ttl: u64,
reason: &'static str,
) {
self.annotate_internal(headers, outcome, hits, ttl, Some(reason), false);
self.annotate_internal(
headers,
outcome,
hits,
ttl as i64,
Some(reason),
false,
None,
);
}
pub fn annotate_reason_transformed(
@@ -194,7 +202,57 @@ impl Settings {
reason: &'static str,
transformed: bool,
) {
self.annotate_internal(headers, outcome, hits, ttl, Some(reason), transformed);
self.annotate_internal(
headers,
outcome,
hits,
ttl as i64,
Some(reason),
transformed,
None,
);
}
pub fn annotate_reason_transformed_freshness(
&self,
headers: &mut HeaderMap,
outcome: &'static str,
hits: u64,
freshness_ttl: i64,
reason: &'static str,
transformed: bool,
) {
self.annotate_internal(
headers,
outcome,
hits,
freshness_ttl,
Some(reason),
transformed,
None,
);
}
pub fn annotate_reason_transformed_forwarded(
&self,
headers: &mut HeaderMap,
outcome: &'static str,
hits: u64,
ttl: u64,
reason: &'static str,
transformed: bool,
forward: &'static str,
forward_status: Option<StatusCode>,
) {
self.annotate_internal(
headers,
outcome,
hits,
ttl as i64,
Some(reason),
transformed,
Some((forward, forward_status)),
);
}
fn annotate_internal(
@@ -202,9 +260,10 @@ impl Settings {
headers: &mut HeaderMap,
outcome: &'static str,
hits: u64,
ttl: u64,
ttl: i64,
reason: Option<&'static str>,
transformed: bool,
forwarded: Option<(&'static str, Option<StatusCode>)>,
) {
if !self.enabled {
return;
@@ -245,15 +304,26 @@ impl Settings {
);
}
if self.expose_cache_status {
let mut value = if matches!(
reason,
Some("cache_revalidated" | "cache_revalidated_uncached")
) {
"RustProxy; fwd=stale; fwd-status=304".to_owned()
let forwarded = forwarded.or_else(|| {
matches!(
reason,
Some("cache_revalidated" | "cache_revalidated_uncached")
)
.then_some(("stale", Some(StatusCode::NOT_MODIFIED)))
});
let mut value = if let Some((why, status)) = forwarded {
let mut value = format!("RustProxy; fwd={why}");
if let Some(status) = status {
value.push_str(&format!("; fwd-status={}", status.as_u16()));
}
value
} else {
match outcome {
"HIT" => format!("RustProxy; hit; ttl={ttl}"),
"MISS" => "RustProxy; fwd=miss".to_owned(),
"BYPASS" if reason == Some("request_method") => {
"RustProxy; fwd=method".to_owned()
}
_ => "RustProxy; fwd=bypass".to_owned(),
}
};