mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(s3): drop omitted system headers on a CopyObject REPLACE copy (#9503)
This commit is contained in:
1 parent
f2125d8908
commit
c63897e171
2 files changed
+84
-5
No files matched your search
@@ -8778,19 +8778,21 @@ public class S3Service implements Resettable, ResourceProvider {
|
||||
metadata.putAll(effectiveOptions.getReplacementMetadata());
|
||||
}
|
||||
|
||||
String effectiveContentType = replaceMetadata && effectiveOptions.getContentType() != null
|
||||
? effectiveOptions.getContentType()
|
||||
// REPLACE takes these headers from the request only; an omitted one is not carried over,
|
||||
// and an omitted Content-Type becomes S3's binary/octet-stream.
|
||||
String effectiveContentType = replaceMetadata
|
||||
? (effectiveOptions.getContentType() != null ? effectiveOptions.getContentType() : "binary/octet-stream")
|
||||
: source.getContentType();
|
||||
String effectiveStorageClass = effectiveOptions.getStorageClass() != null
|
||||
? effectiveOptions.getStorageClass()
|
||||
: source.getStorageClass();
|
||||
String effectiveContentEncoding = replaceMetadata && effectiveOptions.getContentEncoding() != null
|
||||
String effectiveContentEncoding = replaceMetadata
|
||||
? effectiveOptions.getContentEncoding()
|
||||
: source.getContentEncoding();
|
||||
String effectiveContentDisposition = replaceMetadata && effectiveOptions.getContentDisposition() != null
|
||||
String effectiveContentDisposition = replaceMetadata
|
||||
? effectiveOptions.getContentDisposition()
|
||||
: source.getContentDisposition();
|
||||
String effectiveCacheControl = replaceMetadata && effectiveOptions.getCacheControl() != null
|
||||
String effectiveCacheControl = replaceMetadata
|
||||
? effectiveOptions.getCacheControl()
|
||||
: source.getCacheControl();
|
||||
String effectiveSseKmsKeyId = new ObjectEncryption(normalizedServerSideEncryption,
|
||||
|
||||
@@ -1867,6 +1867,83 @@ class S3IntegrationTest {
|
||||
given().delete("/cache-control-bucket");
|
||||
}
|
||||
|
||||
// --- System headers under the copy metadata directive ---
|
||||
|
||||
@Test
|
||||
void copyObjectReplaceDropsOmittedSystemHeaders() {
|
||||
putObjectWithSystemHeaders("replace-headers-bucket");
|
||||
|
||||
given()
|
||||
.header("x-amz-copy-source", "/replace-headers-bucket/source.html")
|
||||
.header("x-amz-metadata-directive", "REPLACE")
|
||||
.header("x-amz-meta-owner", "team-b")
|
||||
.when()
|
||||
.put("/replace-headers-bucket/replaced.html")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("CopyObjectResult"));
|
||||
|
||||
given()
|
||||
.when()
|
||||
.head("/replace-headers-bucket/replaced.html")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.header("x-amz-meta-owner", equalTo("team-b"))
|
||||
.header("Content-Type", equalTo("binary/octet-stream"))
|
||||
.header("Content-Encoding", nullValue())
|
||||
.header("Content-Disposition", nullValue())
|
||||
.header("Cache-Control", nullValue());
|
||||
|
||||
deleteBucketWithKeys("replace-headers-bucket", "source.html", "replaced.html");
|
||||
}
|
||||
|
||||
@Test
|
||||
void copyObjectCopyDirectiveKeepsSystemHeaders() {
|
||||
putObjectWithSystemHeaders("copy-headers-bucket");
|
||||
|
||||
given()
|
||||
.header("x-amz-copy-source", "/copy-headers-bucket/source.html")
|
||||
.header("x-amz-metadata-directive", "COPY")
|
||||
.when()
|
||||
.put("/copy-headers-bucket/copied.html")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("CopyObjectResult"));
|
||||
|
||||
given()
|
||||
.when()
|
||||
.head("/copy-headers-bucket/copied.html")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.header("Content-Type", startsWith("text/html"))
|
||||
.header("Content-Encoding", equalTo("gzip"))
|
||||
.header("Content-Disposition", equalTo("attachment; filename=\"page.html\""))
|
||||
.header("Cache-Control", equalTo("max-age=60"));
|
||||
|
||||
deleteBucketWithKeys("copy-headers-bucket", "source.html", "copied.html");
|
||||
}
|
||||
|
||||
private void putObjectWithSystemHeaders(String bucket) {
|
||||
given().put("/" + bucket).then().statusCode(200);
|
||||
given()
|
||||
.contentType("text/html")
|
||||
.header("Content-Encoding", "gzip")
|
||||
.header("Content-Disposition", "attachment; filename=\"page.html\"")
|
||||
.header("Cache-Control", "max-age=60")
|
||||
.body("<p>page</p>")
|
||||
.when()
|
||||
.put("/" + bucket + "/source.html")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
private void deleteBucketWithKeys(String bucket, String... keys) {
|
||||
for (String key : keys) {
|
||||
given().delete("/" + bucket + "/" + key);
|
||||
}
|
||||
given().delete("/" + bucket);
|
||||
}
|
||||
|
||||
// --- Content-Disposition header preservation ---
|
||||
|
||||
@Test
|
||||
|
||||
Reference in new issue
Block a user