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 d32bc9ff889..15ad2c496b2 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.Response.Status; 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 class ObjectEndpoint extends EndpointBase { } } + 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 446c2c91a1c..6c166d7bc01 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 @@ package org.apache.hadoop.ozone.s3.endpoint; 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 class TestObjectHead { 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