henry3260 commented on code in PR #11157:
URL: https://github.com/apache/ozone/pull/11157#discussion_r3886053283


##########
hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/ObjectEndpoint.java:
##########
@@ -514,6 +517,64 @@ static void addLastModifiedDate(
             RFC1123Util.FORMAT.format(lastModificationTime));
   }
 
+  /**
+   * Adds the {@code x-amz-expiration} header when an enabled lifecycle
+   * expiration rule covers the key, as S3 does: the value names the date the
+   * object is scheduled for deletion and the rule that schedules it. When more
+   * than one rule covers the key, the earliest expiry is reported.
+   * <p>
+   * The header is advisory, so a bucket without a lifecycle configuration, a
+   * caller who may not read it, or any other lookup failure only leaves the
+   * header out; the HEAD itself still succeeds.
+   */
+  private void addExpirationHeader(ResponseBuilder responseBuilder,
+      String bucketName, String keyPath, OzoneKey key) {
+    try {
+      OzoneLifecycleConfiguration lifecycleConfiguration = getClientProtocol()
+          .getLifecycleConfiguration(key.getVolumeName(), bucketName);
+
+      ZonedDateTime earliest = null;
+      String ruleId = null;
+      for (OzoneLifecycleConfiguration.OzoneLCRule rule : 
lifecycleConfiguration.getRules()) {
+        if (!rule.isEnabled() || rule.getExpiration() == null
+            || !rule.matches(keyPath, key.getTags())) {
+          continue;
+        }
+        ZonedDateTime expiryDate = expiryDateOf(rule.getExpiration(), 
key.getModificationTime());
+        if (expiryDate != null && (earliest == null || 
expiryDate.isBefore(earliest))) {
+          earliest = expiryDate;
+          ruleId = rule.getId();
+        }
+      }
+
+      if (earliest != null) {
+        responseBuilder.header(EXPIRATION_HEADER,
+            String.format("expiry-date=\"%s\", rule-id=\"%s\"", 
RFC1123Util.FORMAT.format(earliest), ruleId));

Review Comment:
   > `ruleId` is taken directly from `rule.getId()` without a null guard. If a 
rule ever lacks an ID (not enforced at this layer), the header becomes 
`rule-id="null"`, which is malformed. A simple `continue` when `rule.getId() == 
null` would avoid the bad value and is consistent with how the loop already 
skips rules without expiration.
   
   The id can't be null here `OmLCRule`'s constructor generates a random 48 
character id when none is supplied, and `StringUtils.isEmpty` covers both 
`null` and `""`, so every rule stored in OM has a non-empty id:
   
   
https://github.com/apache/ozone/blob/a17ad8798a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmLCRule.java#L71-L76
   



-- 
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