From a72af60505d43bbfb55afd989498262804d2c80e Mon Sep 17 00:00:00 2001 From: Uddhav Kambli Date: Wed, 28 Dec 2022 10:38:03 -0500 Subject: [PATCH] Custom metadata missing in Public and Signed URLs #1019 (#1020) * Custom metadata missing in Public and Signed URLs #1019 * Update fakestorage/object.go Co-authored-by: Uddhav Kambli Co-authored-by: fsouza <108725+fsouza@users.noreply.github.com> --- 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..6cf298f9e5 100644 --- a/fakestorage/object.go +++ b/fakestorage/object.go @@ -810,6 +810,9 @@ func (s *Server) downloadObject(w http.ResponseWriter, r *http.Request) { 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)) 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 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)