From 3ed71633029e1d2d85b97e77b54e95d474066b4f Mon Sep 17 00:00:00 2001 From: Bharat Viswanadham Date: Wed, 17 Oct 2018 20:44:41 -0700 Subject: [PATCH] HDDS-678. Format of Last-Modified header is invalid in HEAD Object call. Contributed by Elek Marton. --- .../hadoop/ozone/s3/endpoint/ObjectEndpoint.java | 11 ++++++++++- .../hadoop/ozone/s3/endpoint/TestObjectHead.java | 5 +++++ 2 files changed, 15 insertions(+), 1 deletion(-) 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 d32bc9ff88..15ad2c496b 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 @@ -34,6 +34,10 @@ import javax.ws.rs.core.StreamingOutput; import java.io.IOException; import java.io.InputStream; +import java.time.Instant; +import java.time.ZoneId; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.List; @@ -180,8 +184,13 @@ public Response head( } } + ZonedDateTime lastModificationTime = + Instant.ofEpochMilli(key.getModificationTime()) + .atZone(ZoneId.of("GMT")); + return Response.ok().status(HttpStatus.SC_OK) - .header("Last-Modified", key.getModificationTime()) + .header("Last-Modified", + DateTimeFormatter.RFC_1123_DATE_TIME.format(lastModificationTime)) .header("ETag", "" + key.getModificationTime()) .header("Content-Length", key.getDataSize()) .header("Content-Type", "binary/octet-stream") diff --git a/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestObjectHead.java b/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestObjectHead.java index 446c2c91a1..6c166d7bc0 100644 --- a/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestObjectHead.java +++ b/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestObjectHead.java @@ -21,6 +21,7 @@ import javax.ws.rs.core.Response; import java.io.IOException; +import java.time.format.DateTimeFormatter; import org.apache.hadoop.hdds.client.ReplicationFactor; import org.apache.hadoop.hdds.client.ReplicationType; @@ -80,6 +81,10 @@ public void testHeadObject() throws Exception { Assert.assertEquals(200, response.getStatus()); Assert.assertEquals(value.getBytes().length, Long.parseLong(response.getHeaderString("Content-Length"))); + + DateTimeFormatter.RFC_1123_DATE_TIME + .parse(response.getHeaderString("Last-Modified")); + } @Test