From 659e7bfc97b28d2970b23b474b9528d90c3915f8 Mon Sep 17 00:00:00 2001 From: Angira Kekteeva Date: Fri, 5 Aug 2022 05:15:24 +0400 Subject: [PATCH] [#577] Fix version in GetObject and HeadObject Signed-off-by: Angira Kekteeva --- api/handler/get.go | 15 ++++++++++++--- api/handler/head.go | 8 +++++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/api/handler/get.go b/api/handler/get.go index a287c1f..5d40284 100644 --- a/api/handler/get.go +++ b/api/handler/get.go @@ -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 if len(info.ContentType) > 0 && h.Get(api.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.ContentLength, strconv.FormatInt(info.Size, 10)) h.Set(api.ETag, info.HashSum) - h.Set(api.AmzVersionID, extendedInfo.Version()) h.Set(api.AmzTaggingCount, strconv.Itoa(tagSetLength)) + if !isBucketUnversioned { + h.Set(api.AmzVersionID, extendedInfo.Version()) + } + if cacheControl := info.Headers[api.CacheControl]; cacheControl != "" { h.Set(api.CacheControl, cacheControl) } @@ -160,7 +163,13 @@ func (h *handler) GetObjectHandler(w http.ResponseWriter, r *http.Request) { 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 { writeRangeHeaders(w, params, info.Size) } else { diff --git a/api/handler/head.go b/api/handler/head.go index b2ea61a..1854b3d 100644 --- a/api/handler/head.go +++ b/api/handler/head.go @@ -92,7 +92,13 @@ func (h *handler) HeadObjectHandler(w http.ResponseWriter, r *http.Request) { 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) }