[#577] Fix version in GetObject and HeadObject

Signed-off-by: Angira Kekteeva <kira@nspcc.ru>
This commit is contained in:
Angira Kekteeva 2022-08-05 05:15:24 +04:00 committed by Kira
parent dfd734b9ec
commit 659e7bfc97
2 changed files with 19 additions and 4 deletions

View file

@ -71,7 +71,7 @@ func overrideResponseHeaders(h http.Header, query url.Values) {
} }
} }
func writeHeaders(h http.Header, extendedInfo *data.ExtendedObjectInfo, tagSetLength int) { func writeHeaders(h http.Header, extendedInfo *data.ExtendedObjectInfo, tagSetLength int, isBucketUnversioned bool) {
info := extendedInfo.ObjectInfo info := extendedInfo.ObjectInfo
if len(info.ContentType) > 0 && h.Get(api.ContentType) == "" { if len(info.ContentType) > 0 && h.Get(api.ContentType) == "" {
h.Set(api.ContentType, info.ContentType) h.Set(api.ContentType, info.ContentType)
@ -79,9 +79,12 @@ func writeHeaders(h http.Header, extendedInfo *data.ExtendedObjectInfo, tagSetLe
h.Set(api.LastModified, info.Created.UTC().Format(http.TimeFormat)) h.Set(api.LastModified, info.Created.UTC().Format(http.TimeFormat))
h.Set(api.ContentLength, strconv.FormatInt(info.Size, 10)) h.Set(api.ContentLength, strconv.FormatInt(info.Size, 10))
h.Set(api.ETag, info.HashSum) h.Set(api.ETag, info.HashSum)
h.Set(api.AmzVersionID, extendedInfo.Version())
h.Set(api.AmzTaggingCount, strconv.Itoa(tagSetLength)) h.Set(api.AmzTaggingCount, strconv.Itoa(tagSetLength))
if !isBucketUnversioned {
h.Set(api.AmzVersionID, extendedInfo.Version())
}
if cacheControl := info.Headers[api.CacheControl]; cacheControl != "" { if cacheControl := info.Headers[api.CacheControl]; cacheControl != "" {
h.Set(api.CacheControl, cacheControl) h.Set(api.CacheControl, cacheControl)
} }
@ -160,7 +163,13 @@ func (h *handler) GetObjectHandler(w http.ResponseWriter, r *http.Request) {
return return
} }
writeHeaders(w.Header(), extendedInfo, len(tagSet)) bktSettings, err := h.obj.GetBucketSettings(r.Context(), bktInfo)
if err != nil {
h.logAndSendError(w, "could not get bucket settings", reqInfo, err)
return
}
writeHeaders(w.Header(), extendedInfo, len(tagSet), bktSettings.Unversioned())
if params != nil { if params != nil {
writeRangeHeaders(w, params, info.Size) writeRangeHeaders(w, params, info.Size)
} else { } else {

View file

@ -92,7 +92,13 @@ func (h *handler) HeadObjectHandler(w http.ResponseWriter, r *http.Request) {
return return
} }
writeHeaders(w.Header(), extendedInfo, len(tagSet)) bktSettings, err := h.obj.GetBucketSettings(r.Context(), bktInfo)
if err != nil {
h.logAndSendError(w, "could not get bucket settings", reqInfo, err)
return
}
writeHeaders(w.Header(), extendedInfo, len(tagSet), bktSettings.Unversioned())
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
} }