0.34.13_cleaup_code

This commit is contained in:
Mateusz Gruszczyński committed 2026-10-26 14:14:41 +01:00
1 parent ec46a96a29
commit 5c2e50ec06
87 files changed
+4890 -1338

No files matched your search

+30 -9
View File
@@ -182,7 +182,15 @@ impl Settings {
ttl: u64,
reason: &'static str,
) {
self.annotate_internal(headers, outcome, hits, ttl as i64, Some(reason), false, None);
self.annotate_internal(
headers,
outcome,
hits,
ttl as i64,
Some(reason),
false,
None,
);
}
pub fn annotate_reason_transformed(
@@ -194,7 +202,15 @@ impl Settings {
reason: &'static str,
transformed: bool,
) {
self.annotate_internal(headers, outcome, hits, ttl as i64, Some(reason), transformed, None);
self.annotate_internal(
headers,
outcome,
hits,
ttl as i64,
Some(reason),
transformed,
None,
);
}
pub fn annotate_reason_transformed_freshness(
@@ -207,12 +223,16 @@ impl Settings {
transformed: bool,
) {
self.annotate_internal(
headers, outcome, hits, freshness_ttl, Some(reason), transformed, None,
headers,
outcome,
hits,
freshness_ttl,
Some(reason),
transformed,
None,
);
}
// RFC 9211 distinguishes whether this request was forwarded from whether
// the legacy X-Cache metric counted the reused representation as a HIT.
pub fn annotate_reason_transformed_forwarded(
&self,
headers: &mut HeaderMap,
@@ -285,8 +305,11 @@ impl Settings {
}
if self.expose_cache_status {
let forwarded = forwarded.or_else(|| {
matches!(reason, Some("cache_revalidated" | "cache_revalidated_uncached"))
.then_some(("stale", Some(StatusCode::NOT_MODIFIED)))
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}");
@@ -296,8 +319,6 @@ impl Settings {
value
} else {
match outcome {
// RFC 9211 permits a negative ttl when stale data is served
// without sending the current request to the origin.
"HIT" => format!("RustProxy; hit; ttl={ttl}"),
"MISS" => "RustProxy; fwd=miss".to_owned(),
"BYPASS" if reason == Some("request_method") => {
+1 -1
View File
@@ -126,7 +126,7 @@ impl Drop for ColdReadGuard<'_> {
}
}
}
// RFC 9211 uses signed structured-field integers for freshness (negative when stale).
fn cache_status_ttl(ttl: u64, age: u64) -> i64 {
const MAX: i128 = 999_999_999_999_999;
(i128::from(ttl) - i128::from(age)).clamp(-MAX, MAX) as i64
-2
View File
@@ -87,9 +87,7 @@ pub enum ColdPreset {
#[serde(default, deny_unknown_fields)]
pub struct Settings {
pub enabled: bool,
/// Ignore client freshness directives on cache lookups, like Varnish builtin VCL.
pub varnish_compatible: bool,
/// Implicit grace in seconds for eligible fresh-at-storage cached responses.
pub varnish_grace_seconds: u64,
pub memory_preset: Option<MemoryPreset>,
pub max_bytes: usize,
+1 -2
View File
@@ -133,8 +133,7 @@ fn stale_mode(
}
let stale_for = age.saturating_sub(ttl);
let max_stale = client_max_stale(request_headers);
// An explicit client limit must also constrain implicit Varnish grace.
// In particular, max-stale=0 must not serve a stale representation.
if matches!(max_stale, Some(Some(limit)) if stale_for > limit) {
return None;
}