v0.38.7
This commit is contained in:
1 parent
d4a604970e
commit
38a23e2210
40 files changed
+928
-532
No files matched your search
Vendored
+65
@@ -54,6 +54,71 @@ impl Plan {
|
||||
self
|
||||
}
|
||||
}
|
||||
/// For cookie-independent static files only: remove Cookie from the Vary schema
|
||||
/// presented to both RustProxy and downstream caches. A backend's public cache
|
||||
/// policy must be explicit; private/Set-Cookie/no-store responses are untouched.
|
||||
/// The caller is responsible for applying this only to configured static paths.
|
||||
pub fn normalize_static_cookie_vary(
|
||||
status: StatusCode,
|
||||
headers: &mut HeaderMap,
|
||||
settings: &Settings,
|
||||
response_delay: Duration,
|
||||
ignore_static_cookie: bool,
|
||||
overrides: &ResponseOverrides,
|
||||
) -> bool {
|
||||
if !ignore_static_cookie
|
||||
|| !settings.static_ignore_vary_cookie
|
||||
|| !varies_on(headers, "cookie")
|
||||
|| headers.contains_key(::http::header::SET_COOKIE)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
let Some(control) = directives(headers) else {
|
||||
return false;
|
||||
};
|
||||
if !control.contains_key("public")
|
||||
|| control.contains_key("private")
|
||||
|| control.contains_key("no-store")
|
||||
|| control.contains_key("must-understand")
|
||||
|| (settings.varnish_compatible && surrogate_no_store(headers))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
let mut retained = Vec::new();
|
||||
for field in headers.get_all(::http::header::VARY) {
|
||||
let Ok(text) = field.to_str() else { return false; };
|
||||
for part in text.split(',') {
|
||||
let name = part.trim();
|
||||
if name == "*" || name.parse::<http::HeaderName>().is_err() {
|
||||
return false;
|
||||
}
|
||||
if !name.eq_ignore_ascii_case("cookie") {
|
||||
retained.push(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
let mut candidate = headers.clone();
|
||||
candidate.remove(::http::header::VARY);
|
||||
if !retained.is_empty() {
|
||||
let Ok(value) = HeaderValue::from_str(&retained.join(", ")) else {
|
||||
return false;
|
||||
};
|
||||
candidate.insert(::http::header::VARY, value);
|
||||
}
|
||||
// A response may have a storage plan with zero freshness (e.g. `public`
|
||||
// with no fallback TTL, or `max-age=0`). Such a response must retain the
|
||||
// origin's Vary: Cookie. The same applies when reuse needs revalidation.
|
||||
let Some(plan) = plan_with(status, &candidate, settings, response_delay, overrides) else {
|
||||
return false;
|
||||
};
|
||||
if plan.remaining_ttl() == 0 || plan.requires_revalidation {
|
||||
return false;
|
||||
}
|
||||
*headers = candidate;
|
||||
true
|
||||
}
|
||||
|
||||
pub fn plan(
|
||||
status: StatusCode,
|
||||
headers: &HeaderMap,
|
||||
|
||||
Reference in new issue
Block a user