Skip to content

Commit

Permalink
add missing etag header in download object response (#1344)
Browse files Browse the repository at this point in the history
  • Loading branch information
houqp authored Oct 1, 2023
1 parent 44743c5 commit b497e7e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions fakestorage/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,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)
for name, value := range obj.Metadata {
w.Header().Set("X-Goog-Meta-"+name, value)
}
Expand Down
4 changes: 4 additions & 0 deletions fakestorage/object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ 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))
if attrs.Etag != expectedEtag {
t.Errorf("wrong Etag returned\nwant %s\ngot %s", expectedEtag, attrs.Etag)
}
if testObj.Metadata != nil {
if val, err := getMetadataHeaderFromAttrs(attrs, "MetaHeader"); err != nil || val != testObj.Metadata["MetaHeader"] {
t.Errorf("wrong MetaHeader returned\nwant %s\ngot %v", testObj.Metadata["MetaHeader"], val)
Expand Down

0 comments on commit b497e7e

Please sign in to comment.