From 0a1ed04adbc9e3a6b01980f4257ec8830fc97f2e Mon Sep 17 00:00:00 2001 From: Uddhav Kambli Date: Sun, 25 Dec 2022 11:42:39 -0500 Subject: [PATCH 1/2] Custom metadata missing in Public and Signed URLs #1019 --- fakestorage/object.go | 3 +++ fakestorage/object_test.go | 11 +++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/fakestorage/object.go b/fakestorage/object.go index e413f4c4ef..13943a0071 100644 --- a/fakestorage/object.go +++ b/fakestorage/object.go @@ -809,6 +809,9 @@ func (s *Server) downloadObject(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Length", strconv.FormatInt(contentLength, 10)) w.Header().Set("X-Goog-Generation", strconv.FormatInt(obj.Generation, 10)) w.Header().Set("X-Goog-Hash", fmt.Sprintf("crc32c=%s,md5=%s", obj.Crc32c, obj.Md5Hash)) + for name, element := range obj.Metadata { + w.Header().Set("X-Goog-Meta-"+name, element) + } w.Header().Set("Last-Modified", obj.Updated.Format(http.TimeFormat)) if ranged && !satisfiable { diff --git a/fakestorage/object_test.go b/fakestorage/object_test.go index 4d3f3b19cc..19f270d703 100644 --- a/fakestorage/object_test.go +++ b/fakestorage/object_test.go @@ -721,11 +721,18 @@ func TestServerClientObjectReaderError(t *testing.T) { func TestServerClientObjectReadBucketCNAME(t *testing.T) { url := "https://mybucket.mydomain.com:4443/files/txt/text-01.txt" - expectedHeaders := map[string]string{"accept-ranges": "bytes", "content-length": "9"} + expectedHeaders := map[string]string{"accept-ranges": "bytes", "content-length": "9", "x-goog-meta-marco": "Polo"} expectedBody := "something" opts := Options{ InitialObjects: []Object{ - {ObjectAttrs: ObjectAttrs{BucketName: "mybucket.mydomain.com", Name: "files/txt/text-01.txt"}, Content: []byte("something")}, + { + ObjectAttrs: ObjectAttrs{ + BucketName: "mybucket.mydomain.com", + Name: "files/txt/text-01.txt", + Metadata: map[string]string{"Marco": "Polo"}, + }, + Content: []byte("something"), + }, }, } server, err := NewServerWithOptions(opts) From 46ae8e208b506e3ccab9f6363ab0f251678bb445 Mon Sep 17 00:00:00 2001 From: fsouza <108725+fsouza@users.noreply.github.com> Date: Wed, 28 Dec 2022 10:31:48 -0500 Subject: [PATCH 2/2] Update fakestorage/object.go --- fakestorage/object.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fakestorage/object.go b/fakestorage/object.go index 13943a0071..6cf298f9e5 100644 --- a/fakestorage/object.go +++ b/fakestorage/object.go @@ -809,10 +809,10 @@ func (s *Server) downloadObject(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Length", strconv.FormatInt(contentLength, 10)) w.Header().Set("X-Goog-Generation", strconv.FormatInt(obj.Generation, 10)) w.Header().Set("X-Goog-Hash", fmt.Sprintf("crc32c=%s,md5=%s", obj.Crc32c, obj.Md5Hash)) - for name, element := range obj.Metadata { - w.Header().Set("X-Goog-Meta-"+name, element) - } w.Header().Set("Last-Modified", obj.Updated.Format(http.TimeFormat)) + for name, value := range obj.Metadata { + w.Header().Set("X-Goog-Meta-"+name, value) + } if ranged && !satisfiable { status = http.StatusRequestedRangeNotSatisfiable