From 7f6fc13b1ebaa8753b35f1cd80dcaefa4ea24943 Mon Sep 17 00:00:00 2001 From: Ivan Andika Date: Thu, 14 Mar 2024 16:05:26 +0800 Subject: [PATCH] HDDS-10521. ETag field should not be returned during GetObject if the key does not contain ETag field --- .../hadoop/ozone/s3/endpoint/ObjectEndpoint.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/ObjectEndpoint.java b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/ObjectEndpoint.java index 47be6aeb6df..81e49d64f7c 100644 --- a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/ObjectEndpoint.java +++ b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/ObjectEndpoint.java @@ -483,9 +483,12 @@ public Response get( responseBuilder.header(CONTENT_RANGE_HEADER, contentRangeVal); } responseBuilder - .header(ETAG, wrapInQuotes(keyDetails.getMetadata().get(ETAG))) .header(ACCEPT_RANGE_HEADER, RANGE_HEADER_SUPPORTED_UNIT); + if (keyDetails.getMetadata().get(ETAG) != null) { + responseBuilder.header(ETAG, wrapInQuotes(keyDetails.getMetadata().get(ETAG))); + } + // if multiple query parameters having same name, // Only the first parameters will be recognized // eg: @@ -591,9 +594,16 @@ public Response head( } ResponseBuilder response = Response.ok().status(HttpStatus.SC_OK) - .header(ETAG, "" + wrapInQuotes(key.getMetadata().get(ETAG))) .header("Content-Length", key.getDataSize()) .header("Content-Type", "binary/octet-stream"); + + if (key.getMetadata().get(ETAG) != null) { + // Should not return ETag header if the ETag is not set + // doing so will result in "null" string being returned instead + // which breaks some AWS SDK implementation + response.header(ETAG, "" + wrapInQuotes(key.getMetadata().get(ETAG))); + } + addLastModifiedDate(response, key); addCustomMetadataHeaders(response, key); getMetrics().updateHeadKeySuccessStats(startNanos);