From 9ca1e37235e0b626cbf2ce502e0fb1279e562440 Mon Sep 17 00:00:00 2001 From: "Frederick F. Kautz IV" Date: Wed, 21 Jan 2015 15:02:08 -0800 Subject: [PATCH] Adding etag to headers --- pkg/storage/inmemory/inmemory.go | 6 ++++++ pkg/storage/storage.go | 1 + pkg/webapi/minioapi/minioapi.go | 5 +++++ 3 files changed, 12 insertions(+) diff --git a/pkg/storage/inmemory/inmemory.go b/pkg/storage/inmemory/inmemory.go index 913542ca3..003a87d33 100644 --- a/pkg/storage/inmemory/inmemory.go +++ b/pkg/storage/inmemory/inmemory.go @@ -150,3 +150,9 @@ func isValidBucket(bucket string) bool { } return valid } + +func (storage *Storage) GetObjectMetadata(bucket, key string) mstorage.ObjectMetadata { + objectKey := bucket + ":" + key + + return storage.objectdata[objectKey].metadata +} diff --git a/pkg/storage/storage.go b/pkg/storage/storage.go index 226e0e4b9..f02760789 100644 --- a/pkg/storage/storage.go +++ b/pkg/storage/storage.go @@ -26,6 +26,7 @@ type Storage interface { ListBuckets(prefix string) []BucketMetadata // Object Operations + GetObjectMetadata(bucket string, object string) ObjectMetadata CopyObjectToWriter(w io.Writer, bucket string, object string) (int64, error) StoreObject(bucket string, key string, data io.Reader) error ListObjects(bucket, prefix string, count int) []ObjectMetadata diff --git a/pkg/webapi/minioapi/minioapi.go b/pkg/webapi/minioapi/minioapi.go index 5afde58e1..ee8cc2882 100644 --- a/pkg/webapi/minioapi/minioapi.go +++ b/pkg/webapi/minioapi/minioapi.go @@ -55,6 +55,11 @@ func (server *minioApi) getObjectHandler(w http.ResponseWriter, req *http.Reques bucket := vars["bucket"] object := vars["object"] + metadata := server.storage.GetObjectMetadata(bucket, object) + lastModifiedTime := time.Unix(metadata.SecCreated, 0) + lastModified := lastModifiedTime.Format(time.RFC1123) + w.Header().Set("ETag", metadata.ETag) + w.Header().Set("Last-Modified", lastModified) _, err := server.storage.CopyObjectToWriter(w, bucket, object) switch err := err.(type) { case nil: // success