v0.34.7
This commit is contained in:
1 parent
1cd6b7ac99
commit
58c7d63194
5 files changed
+281
-71
No files matched your search
@@ -614,7 +614,10 @@ mod cache_fast_path_tests {
|
||||
.await;
|
||||
assert_eq!(validated.status, StatusCode::OK);
|
||||
assert_eq!(validated.headers["x-cache"], "HIT");
|
||||
assert_eq!(validated.headers["x-cache-reason"], "cache_hit", "default compatibility mode must not revalidate a fresh object");
|
||||
assert_eq!(
|
||||
validated.headers["x-cache-reason"], "cache_hit",
|
||||
"default compatibility mode must not revalidate a fresh object"
|
||||
);
|
||||
assert_eq!(validated.body, "origin-a");
|
||||
let conditional = fixture
|
||||
.get(
|
||||
@@ -641,17 +644,29 @@ mod cache_fast_path_tests {
|
||||
async fn compatible_only_if_cached_on_miss_never_contacts_origin() {
|
||||
let origin = origin().await;
|
||||
let fixture = Fixture::new(config_for(origin.addr, true)).await;
|
||||
let miss = fixture.get("/missing", &[("cache-control", "no-cache, only-if-cached")]).await;
|
||||
let miss = fixture
|
||||
.get("/missing", &[("cache-control", "no-cache, only-if-cached")])
|
||||
.await;
|
||||
assert_eq!(miss.status, StatusCode::GATEWAY_TIMEOUT);
|
||||
assert_eq!(origin.requests.load(Ordering::Relaxed), 0, "only-if-cached MISS must not contact backend");
|
||||
assert_eq!(
|
||||
origin.requests.load(Ordering::Relaxed),
|
||||
0,
|
||||
"only-if-cached MISS must not contact backend"
|
||||
);
|
||||
let primed = fixture.get("/vary", &[]).await;
|
||||
assert_eq!(primed.headers["x-cache"], "MISS");
|
||||
let hit = fixture.get("/vary", &[("cache-control", "only-if-cached")]).await;
|
||||
let hit = fixture
|
||||
.get("/vary", &[("cache-control", "only-if-cached")])
|
||||
.await;
|
||||
assert_eq!(hit.headers["x-cache"], "HIT");
|
||||
assert_eq!(origin.requests.load(Ordering::Relaxed), 1);
|
||||
let blocked = fixture.get("/vary", &[("cache-control", "no-store")]).await;
|
||||
assert_eq!(blocked.headers["x-cache-reason"], "request_no_store");
|
||||
assert_eq!(origin.requests.load(Ordering::Relaxed), 2, "no-store must bypass even a fresh HIT");
|
||||
assert_eq!(
|
||||
origin.requests.load(Ordering::Relaxed),
|
||||
2,
|
||||
"no-store must bypass even a fresh HIT"
|
||||
);
|
||||
fixture.stop().await;
|
||||
}
|
||||
|
||||
@@ -661,7 +676,10 @@ mod cache_fast_path_tests {
|
||||
let mut config = config_for(origin.addr, true);
|
||||
config.cache.default_ttl_seconds = 0;
|
||||
let fixture = Fixture::new(config).await;
|
||||
assert_eq!(fixture.get("/backend-no-cache", &[]).await.headers["x-cache"], "MISS");
|
||||
assert_eq!(
|
||||
fixture.get("/backend-no-cache", &[]).await.headers["x-cache"],
|
||||
"MISS"
|
||||
);
|
||||
let cached_only = fixture
|
||||
.get("/backend-no-cache", &[("cache-control", "only-if-cached")])
|
||||
.await;
|
||||
@@ -678,11 +696,18 @@ mod cache_fast_path_tests {
|
||||
let mut config = config_for(origin.addr, true);
|
||||
config.cache.default_ttl_seconds = 45;
|
||||
let fixture = Fixture::new(config).await;
|
||||
assert_eq!(fixture.get("/backend-no-cache", &[]).await.headers["x-cache"], "MISS");
|
||||
assert_eq!(
|
||||
fixture.get("/backend-no-cache", &[]).await.headers["x-cache"],
|
||||
"MISS"
|
||||
);
|
||||
let reused = fixture.get("/backend-no-cache", &[]).await;
|
||||
assert_eq!(reused.headers["x-cache"], "HIT");
|
||||
assert_eq!(reused.headers["x-cache-reason"], "cache_hit");
|
||||
assert_eq!(origin.requests.load(Ordering::Relaxed), 1, "configured fallback TTL avoids origin revalidation");
|
||||
assert_eq!(
|
||||
origin.requests.load(Ordering::Relaxed),
|
||||
1,
|
||||
"configured fallback TTL avoids origin revalidation"
|
||||
);
|
||||
fixture.stop().await;
|
||||
}
|
||||
|
||||
@@ -692,12 +717,21 @@ mod cache_fast_path_tests {
|
||||
let fixture = Fixture::new(config_for(origin.addr, true)).await;
|
||||
assert_eq!(fixture.get("/grace", &[]).await.headers["x-cache"], "MISS");
|
||||
tokio::time::sleep(Duration::from_millis(1200)).await;
|
||||
let stale = fixture.get("/grace", &[("cache-control", "only-if-cached")]).await;
|
||||
let stale = fixture
|
||||
.get("/grace", &[("cache-control", "only-if-cached")])
|
||||
.await;
|
||||
assert_eq!(stale.status, StatusCode::OK);
|
||||
assert_eq!(stale.headers["x-cache"], "HIT");
|
||||
assert_eq!(stale.headers["x-cache-reason"], "cache_stale_while_revalidate");
|
||||
assert_eq!(
|
||||
stale.headers["x-cache-reason"],
|
||||
"cache_stale_while_revalidate"
|
||||
);
|
||||
tokio::time::sleep(Duration::from_millis(100)).await;
|
||||
assert_eq!(origin.requests.load(Ordering::Relaxed), 1, "only-if-cached must not start async validation");
|
||||
assert_eq!(
|
||||
origin.requests.load(Ordering::Relaxed),
|
||||
1,
|
||||
"only-if-cached must not start async validation"
|
||||
);
|
||||
fixture.stop().await;
|
||||
}
|
||||
|
||||
@@ -705,14 +739,32 @@ mod cache_fast_path_tests {
|
||||
async fn web_server_only_if_cached_on_miss_never_reads_origin() {
|
||||
let directory = TempDir::new().unwrap();
|
||||
let fixture = Fixture::new(web_config(&directory, true)).await;
|
||||
let miss = fixture.get("/style.css", &[("cache-control", "only-if-cached")]).await;
|
||||
let miss = fixture
|
||||
.get("/style.css", &[("cache-control", "only-if-cached")])
|
||||
.await;
|
||||
assert_eq!(miss.status, StatusCode::GATEWAY_TIMEOUT);
|
||||
assert_eq!(fixture.get("/style.css", &[]).await.headers["x-cache"], "MISS");
|
||||
let hit = fixture.get("/style.css", &[("cache-control", "only-if-cached")]).await;
|
||||
assert_eq!(
|
||||
fixture.get("/style.css", &[]).await.headers["x-cache"],
|
||||
"MISS"
|
||||
);
|
||||
let hit = fixture
|
||||
.get("/style.css", &[("cache-control", "only-if-cached")])
|
||||
.await;
|
||||
assert_eq!(hit.headers["x-cache"], "HIT");
|
||||
let bypass = fixture.get("/style.css", &[("cache-control", "no-store, only-if-cached")]).await;
|
||||
assert_eq!(bypass.status, StatusCode::GATEWAY_TIMEOUT, "uncacheable only-if-cached must not read the Web Server file");
|
||||
let reload = fixture.get("/style.css", &[("cache-control", "no-cache")]).await;
|
||||
let bypass = fixture
|
||||
.get(
|
||||
"/style.css",
|
||||
&[("cache-control", "no-store, only-if-cached")],
|
||||
)
|
||||
.await;
|
||||
assert_eq!(
|
||||
bypass.status,
|
||||
StatusCode::GATEWAY_TIMEOUT,
|
||||
"uncacheable only-if-cached must not read the Web Server file"
|
||||
);
|
||||
let reload = fixture
|
||||
.get("/style.css", &[("cache-control", "no-cache")])
|
||||
.await;
|
||||
assert_eq!(reload.headers["x-cache-reason"], "cache_hit");
|
||||
fixture.stop().await;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user