implement conditional put/patch

Signed-off-by: Alexander Onnikov <Alexander.Onnikov@xored.com>
This commit is contained in:
Alexander Onnikov
2025-09-22 23:41:20 +07:00
parent 2469c00b1d
commit 72dae37dd6
8 changed files with 542 additions and 48 deletions
+45
View File
@@ -64,3 +64,48 @@ pub async fn head_known_with_jsonpatch() -> eyre::Result<()> {
Ok(())
}
#[tanu::test]
pub async fn head_conditional() -> eyre::Result<()> {
let key = random_key();
let text = random_text(1024);
let http = Client::new();
let res = http.key_put(&key).body(text.clone()).send().await?;
check!(res.status().is_success());
let res = http.key_head(&key).send().await?;
check!(res.status().is_success());
let etag = res.header("etag").expect("ETag not found");
// Test without If-None-Match (normal GET)
let res = http.key_head(&key).send().await?;
check!(res.status().is_success());
// Test with If-None-Match: *
let res = http
.key_head(&key)
.header("If-None-Match", "*")
.send()
.await?;
check_eq!(res.status(), http::StatusCode::NOT_MODIFIED);
// Test with correct ETag
let res = http
.key_head(&key)
.header("If-None-Match", etag)
.send()
.await?;
check_eq!(res.status(), http::StatusCode::NOT_MODIFIED);
// Test with incorrect ETag
let res = http
.key_head(&key)
.header("If-None-Match", "\"invalid-etag\"")
.send()
.await?;
check!(res.status().is_success());
Ok(())
}