Add x-amz-expiration header in some S3 responses (#9667)

x-amz-expiration is described in the S3 specification as a header which
indicates if the object in question will expire any time in the future.
This commit is contained in:
Anis Elleuch
2020-05-21 22:12:52 +01:00
committed by GitHub
parent fade056244
commit cdf4815a6b
5 changed files with 87 additions and 7 deletions
+14
View File
@@ -18,6 +18,7 @@ package cmd
import (
"context"
"fmt"
"net/http"
"regexp"
"time"
@@ -252,6 +253,19 @@ func isETagEqual(left, right string) bool {
return canonicalizeETag(left) == canonicalizeETag(right)
}
// setAmzExpirationHeader sets x-amz-expiration header with expiry time
// after analyzing the current bucket lifecycle rules if any.
func setAmzExpirationHeader(w http.ResponseWriter, bucket string, objInfo ObjectInfo) {
if lc, err := globalLifecycleSys.Get(bucket); err == nil {
ruleID, expiryTime := lc.PredictExpiryTime(objInfo.Name, objInfo.UserTags)
if !expiryTime.IsZero() {
w.Header()[xhttp.AmzExpiration] = []string{
fmt.Sprintf(`expiry-date="%s", rule-id="%s"`, expiryTime.Format(http.TimeFormat), ruleID),
}
}
}
}
// deleteObject is a convenient wrapper to delete an object, this
// is a common function to be called from object handlers and
// web handlers.