fix(s3): implement TaggingDirective=COPY default in CopyObject (#1049)

* fix(s3): implement TaggingDirective=COPY default in CopyObject
This commit is contained in:
Ed Jeffreys authored and GitHub committed 2026-05-26 21:37:37 -05:00
1 parent 4aea1c7c37
commit 37f37d1292
5 files changed
+166 -1

No files matched your search

@@ -1619,11 +1619,18 @@ public class S3Controller {
String copyCacheControl = httpHeaders.getHeaderString("Cache-Control");
String copyServerSideEncryption = httpHeaders.getHeaderString("x-amz-server-side-encryption");
String cannedAcl = httpHeaders.getHeaderString("x-amz-acl");
String taggingDirective = httpHeaders.getHeaderString("x-amz-tagging-directive");
String taggingHeader = httpHeaders.getHeaderString("x-amz-tagging");
Map<String, String> replacementTagging = "REPLACE".equalsIgnoreCase(taggingDirective)
? (taggingHeader != null ? parseInlineTaggingHeader(taggingHeader) : Map.of())
: null;
S3Object copy = s3Service.copyObject(sourceBucket, sourceObject.objectKey(), destBucket, destKey,
sourceObject.versionId(),
new CopyObjectOptions()
.withMetadataDirective(httpHeaders.getHeaderString("x-amz-metadata-directive"))
.withReplacementMetadata(extractUserMetadata(httpHeaders))
.withTaggingDirective(taggingDirective)
.withReplacementTagging(replacementTagging)
.withStorageClass(httpHeaders.getHeaderString("x-amz-storage-class"))
.withContentType(contentType)
.withContentEncoding(copyContentEncoding)
@@ -2135,6 +2135,11 @@ public class S3Service {
String effectiveServerSideEncryption = normalizedServerSideEncryption != null
? normalizedServerSideEncryption
: source.getServerSideEncryption();
boolean replaceTags = "REPLACE".equalsIgnoreCase(effectiveOptions.getTaggingDirective());
Map<String, String> effectiveTags = replaceTags
? effectiveOptions.getReplacementTagging()
: source.getTags();
S3Object copy = storeObject(destBucket, destKey, source.getData(), effectiveContentType, metadata,
source.getChecksum(), source.getParts(),
new PutObjectOptions()
@@ -2143,7 +2148,8 @@ public class S3Service {
.withContentDisposition(effectiveContentDisposition)
.withCacheControl(effectiveCacheControl)
.withServerSideEncryption(effectiveServerSideEncryption)
.withAcl(effectiveOptions.getAcl()));
.withAcl(effectiveOptions.getAcl())
.withTagging(effectiveTags));
copy.setETag(source.getETag());
LOG.debugv("Copied object: {0}/{1} -> {2}/{3}", sourceBucket, sourceKey, destBucket, destKey);
fireNotifications(destBucket, destKey, "ObjectCreated:Copy", copy);
@@ -5,6 +5,8 @@ import java.util.Map;
public class CopyObjectOptions {
private String metadataDirective;
private Map<String, String> replacementMetadata;
private String taggingDirective;
private Map<String, String> replacementTagging;
private String storageClass;
private String contentType;
private String contentEncoding;
@@ -19,6 +21,12 @@ public class CopyObjectOptions {
public Map<String, String> getReplacementMetadata() { return replacementMetadata; }
public CopyObjectOptions withReplacementMetadata(Map<String, String> replacementMetadata) { this.replacementMetadata = replacementMetadata; return this; }
public String getTaggingDirective() { return taggingDirective; }
public CopyObjectOptions withTaggingDirective(String taggingDirective) { this.taggingDirective = taggingDirective; return this; }
public Map<String, String> getReplacementTagging() { return replacementTagging; }
public CopyObjectOptions withReplacementTagging(Map<String, String> replacementTagging) { this.replacementTagging = replacementTagging; return this; }
public String getStorageClass() { return storageClass; }
public CopyObjectOptions withStorageClass(String storageClass) { this.storageClass = storageClass; return this; }