diff --git a/fakestorage/object.go b/fakestorage/object.go index c433a626e4..c7b4095323 100644 --- a/fakestorage/object.go +++ b/fakestorage/object.go @@ -854,7 +854,7 @@ 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)) - w.Header().Set("ETag", obj.Etag) + w.Header().Set("ETag", fmt.Sprintf("%q", obj.Etag)) for name, value := range obj.Metadata { w.Header().Set("X-Goog-Meta-"+name, value) } diff --git a/fakestorage/object_test.go b/fakestorage/object_test.go index b1581583ed..2497be52d3 100644 --- a/fakestorage/object_test.go +++ b/fakestorage/object_test.go @@ -177,7 +177,7 @@ func checkObjectAttrs(testObj Object, attrs *storage.ObjectAttrs, t *testing.T) if testObj.Content != nil && !bytes.Equal(attrs.MD5, checksum.MD5Hash(testObj.Content)) { t.Errorf("wrong hash returned\nwant %d\ngot %d", checksum.MD5Hash(testObj.Content), attrs.MD5) } - expectedEtag := fmt.Sprintf("\"%s\"", checksum.EncodedHash(attrs.MD5)) + expectedEtag := checksum.EncodedHash(attrs.MD5) if attrs.Etag != expectedEtag { t.Errorf("wrong Etag returned\nwant %s\ngot %s", expectedEtag, attrs.Etag) } diff --git a/fakestorage/upload.go b/fakestorage/upload.go index 3aaeb0f027..c85de72abb 100644 --- a/fakestorage/upload.go +++ b/fakestorage/upload.go @@ -504,7 +504,7 @@ func (s *Server) uploadFileContent(r *http.Request) jsonResponse { obj.Content = append(obj.Content, content...) obj.Crc32c = checksum.EncodedCrc32cChecksum(obj.Content) obj.Md5Hash = checksum.EncodedMd5Hash(obj.Content) - obj.Etag = fmt.Sprintf("%q", obj.Md5Hash) + obj.Etag = obj.Md5Hash contentTypeHeader := r.Header.Get(contentTypeHeader) if contentTypeHeader != "" { obj.ContentType = contentTypeHeader diff --git a/internal/backend/fs.go b/internal/backend/fs.go index 64f1106820..c96867d802 100644 --- a/internal/backend/fs.go +++ b/internal/backend/fs.go @@ -251,7 +251,7 @@ func (s *storageFS) CreateObject(obj StreamingObject, conditions Conditions) (St obj.Md5Hash = hasher.EncodedMd5Hash() } if obj.Etag == "" { - obj.Etag = fmt.Sprintf("%q", obj.Md5Hash) + obj.Etag = obj.Md5Hash } // TODO: Handle if metadata is not present more gracefully? diff --git a/internal/backend/memory.go b/internal/backend/memory.go index 5075bf1965..c32f06abf2 100644 --- a/internal/backend/memory.go +++ b/internal/backend/memory.go @@ -44,7 +44,7 @@ func (bm *bucketInMemory) addObject(obj Object) Object { obj.Md5Hash = checksum.EncodedMd5Hash(obj.Content) } if obj.Etag == "" { - obj.Etag = fmt.Sprintf("%q", obj.Md5Hash) + obj.Etag = obj.Md5Hash } if obj.Size == 0 { obj.Size = int64(len(obj.Content))