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

View File

@@ -427,6 +427,7 @@ func (api objectAPIHandlers) GetObjectHandler(w http.ResponseWriter, r *http.Req
}
setHeadGetRespHeaders(w, r.URL.Query())
setAmzExpirationHeader(w, bucket, objInfo)
statusCodeWritten := false
httpWriter := ioutil.WriteOnClose(w)
@@ -606,6 +607,9 @@ func (api objectAPIHandlers) HeadObjectHandler(w http.ResponseWriter, r *http.Re
// Set any additional requested response headers.
setHeadGetRespHeaders(w, r.URL.Query())
// Set the expiration header
setAmzExpirationHeader(w, bucket, objInfo)
// Successful response.
if rs != nil {
w.WriteHeader(http.StatusPartialContent)
@@ -1165,6 +1169,8 @@ func (api objectAPIHandlers) CopyObjectHandler(w http.ResponseWriter, r *http.Re
}
}
setAmzExpirationHeader(w, dstBucket, objInfo)
response := generateCopyObjectResponse(getDecryptedETag(r.Header, objInfo, false), objInfo.ModTime)
encodedSuccessResponse := encodeResponse(response)
@@ -1476,10 +1482,14 @@ func (api objectAPIHandlers) PutObjectHandler(w http.ResponseWriter, r *http.Req
}
}
}
// We must not use the http.Header().Set method here because some (broken)
// clients expect the ETag header key to be literally "ETag" - not "Etag" (case-sensitive).
// Therefore, we have to set the ETag directly as map entry.
w.Header()[xhttp.ETag] = []string{`"` + etag + `"`}
setAmzExpirationHeader(w, bucket, objInfo)
writeSuccessResponseHeadersOnly(w)
// Notify object created event.
@@ -2526,6 +2536,8 @@ func (api objectAPIHandlers) CompleteMultipartUploadHandler(w http.ResponseWrite
// Set etag.
w.Header()[xhttp.ETag] = []string{"\"" + objInfo.ETag + "\""}
setAmzExpirationHeader(w, bucket, objInfo)
// Write success response.
writeSuccessResponseXML(w, encodedSuccessResponse)