feat(s3): preserve Cache-Control header on PutObject, GetObject, HeadObject, and CopyObject (#313)

Add cacheControl as a dedicated field on S3Object (following the
contentEncoding pattern) and thread it through putObject, storeObject,
and copyObject in S3Service. Extract Cache-Control from request headers
in S3Controller.putObject, return it in appendObjectHeaders for
GetObject/HeadObject responses, and handle it in handleCopyObject with
REPLACE directive support.

Includes 6 integration tests covering put, get, head, copy-preserve,
copy-replace, and cleanup.
This commit is contained in:
Matej Šnuderl authored and GitHub committed 2026-04-09 19:43:08 -05:00
1 parent a770b61a7b
commit 89a07448c0
4 files changed
+122 -14

No files matched your search

@@ -898,6 +898,98 @@ class S3IntegrationTest {
given().delete("/encoding-test-bucket");
}
// --- Cache-Control header preservation ---
@Test
@Order(89)
void createCacheControlBucketAndPutObject() {
given()
.put("/cache-control-bucket")
.then()
.statusCode(200);
given()
.contentType("text/plain")
.header("Cache-Control", "public, max-age=31536000")
.body("cached-content")
.when()
.put("/cache-control-bucket/cached.txt")
.then()
.statusCode(200)
.header("ETag", notNullValue());
}
@Test
@Order(90)
void getObjectReturnsCacheControl() {
given()
.when()
.get("/cache-control-bucket/cached.txt")
.then()
.statusCode(200)
.header("Cache-Control", equalTo("public, max-age=31536000"));
}
@Test
@Order(90)
void headObjectReturnsCacheControl() {
given()
.when()
.head("/cache-control-bucket/cached.txt")
.then()
.statusCode(200)
.header("Cache-Control", equalTo("public, max-age=31536000"));
}
@Test
@Order(91)
void copyObjectPreservesCacheControl() {
given()
.header("x-amz-copy-source", "/cache-control-bucket/cached.txt")
.when()
.put("/cache-control-bucket/cached-copy.txt")
.then()
.statusCode(200)
.body(containsString("CopyObjectResult"));
given()
.when()
.head("/cache-control-bucket/cached-copy.txt")
.then()
.statusCode(200)
.header("Cache-Control", equalTo("public, max-age=31536000"));
}
@Test
@Order(91)
void copyObjectReplaceCacheControl() {
given()
.header("x-amz-copy-source", "/cache-control-bucket/cached.txt")
.header("x-amz-metadata-directive", "REPLACE")
.header("Cache-Control", "no-cache")
.when()
.put("/cache-control-bucket/cached-nocache.txt")
.then()
.statusCode(200)
.body(containsString("CopyObjectResult"));
given()
.when()
.head("/cache-control-bucket/cached-nocache.txt")
.then()
.statusCode(200)
.header("Cache-Control", equalTo("no-cache"));
}
@Test
@Order(92)
void cleanupCacheControlBucket() {
given().delete("/cache-control-bucket/cached.txt");
given().delete("/cache-control-bucket/cached-copy.txt");
given().delete("/cache-control-bucket/cached-nocache.txt");
given().delete("/cache-control-bucket");
}
// --- S3 Notification Configuration with Filter ---
@Test