adoroszlai commented on code in PR #12170:
URL: https://github.com/apache/ozone/pull/12170#discussion_r4801931894


##########
hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/ObjectEndpoint.java:
##########
@@ -534,6 +540,22 @@ static void addLastModifiedDate(
             RFC1123Util.FORMAT.format(lastModificationTime));
   }
 
+  /**
+   * Adds the {@code x-amz-expiration} header, e.g. {@code expiry-date="Fri, 
27 Nov 2026 00:00:00 GMT",
+   * rule-id="rule1"}, if an enabled lifecycle Expiration rule of the bucket 
applies to the key.
+   * As in AWS S3, the rule ID is URL-encoded.
+   */
+  static void addExpirationIfAny(ResponseBuilder responseBuilder, 
S3KeyReadResult<?> readResult)
+      throws UnsupportedEncodingException {
+    LifecycleExpirationInfo expiration = 
readResult.getLifecycleExpiration().orElse(null);
+    if (expiration == null) {
+      return;
+    }
+    ZonedDateTime expiryTime = 
expiration.getExpiryTime().atZone(ZoneId.of(OzoneConsts.OZONE_TIME_ZONE));
+    responseBuilder.header(EXPIRATION_HEADER, "expiry-date=\"" + 
RFC1123Util.FORMAT.format(expiryTime)
+        + "\", rule-id=\"" + S3Utils.s3urlEncode(expiration.getRuleId()) + 
"\"");

Review Comment:
   nit: Since `getLifecycleExpiration` returns `Optional`, replace `null` check 
with `ifPresent`:
   
   (May create helper method to avoid the block lambda.)
   
   ```java
   readResult.getLifecycleExpiration().ifPresent(expiration -> {
     ZonedDateTime expiryTime = 
expiration.getExpiryTime().atZone(ZoneId.of(OzoneConsts.OZONE_TIME_ZONE));
     responseBuilder.header(EXPIRATION_HEADER, "expiry-date=\"" + 
RFC1123Util.FORMAT.format(expiryTime)
         + "\", rule-id=\"" + S3Utils.s3urlEncode(expiration.getRuleId()) + 
"\"");
   });
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to