Performing etag off of bytes rather than md5 string

master
Frederick F. Kautz IV 10 years ago
parent 583c32c774
commit 211b084e50
  1. 19
      pkg/api/minioapi/api_test.go
  2. 7
      pkg/api/minioapi/headers.go
  3. 3
      pkg/api/minioapi/response.go

@ -33,6 +33,7 @@ import (
"github.com/minio-io/minio/pkg/storage/memory" "github.com/minio-io/minio/pkg/storage/memory"
"encoding/base64" "encoding/base64"
"encoding/hex"
. "gopkg.in/check.v1" . "gopkg.in/check.v1"
) )
@ -74,7 +75,7 @@ func (s *MySuite) TestEmptyObject(c *C) {
metadata, err := storage.GetObjectMetadata("bucket", "object", "") metadata, err := storage.GetObjectMetadata("bucket", "object", "")
c.Assert(err, IsNil) c.Assert(err, IsNil)
verifyHeaders(c, response.Header, metadata.Created, 0, "application/octet-stream", base64.StdEncoding.EncodeToString([]byte(metadata.Md5))) verifyHeaders(c, response.Header, metadata.Created, 0, "application/octet-stream", metadata.Md5)
// TODO Test Headers // TODO Test Headers
} }
@ -99,7 +100,7 @@ func (s *MySuite) TestObject(c *C) {
metadata, err := storage.GetObjectMetadata("bucket", "object", "") metadata, err := storage.GetObjectMetadata("bucket", "object", "")
c.Assert(err, IsNil) c.Assert(err, IsNil)
verifyHeaders(c, response.Header, metadata.Created, len("hello world"), "application/octet-stream", base64.StdEncoding.EncodeToString([]byte(metadata.Md5))) verifyHeaders(c, response.Header, metadata.Created, len("hello world"), "application/octet-stream", metadata.Md5)
} }
func (s *MySuite) TestMultipleObjects(c *C) { func (s *MySuite) TestMultipleObjects(c *C) {
@ -135,7 +136,7 @@ func (s *MySuite) TestMultipleObjects(c *C) {
c.Assert(response.StatusCode, Equals, http.StatusOK) c.Assert(response.StatusCode, Equals, http.StatusOK)
// verify headers // verify headers
verifyHeaders(c, response.Header, metadata.Created, len("hello one"), "application/octet-stream", base64.StdEncoding.EncodeToString([]byte(metadata.Md5))) verifyHeaders(c, response.Header, metadata.Created, len("hello one"), "application/octet-stream", metadata.Md5)
c.Assert(err, IsNil) c.Assert(err, IsNil)
// verify response data // verify response data
@ -154,7 +155,7 @@ func (s *MySuite) TestMultipleObjects(c *C) {
c.Assert(response.StatusCode, Equals, http.StatusOK) c.Assert(response.StatusCode, Equals, http.StatusOK)
// verify headers // verify headers
verifyHeaders(c, response.Header, metadata.Created, len("hello two"), "application/octet-stream", base64.StdEncoding.EncodeToString([]byte(metadata.Md5))) verifyHeaders(c, response.Header, metadata.Created, len("hello two"), "application/octet-stream", metadata.Md5)
c.Assert(err, IsNil) c.Assert(err, IsNil)
// verify response data // verify response data
@ -173,7 +174,7 @@ func (s *MySuite) TestMultipleObjects(c *C) {
c.Assert(response.StatusCode, Equals, http.StatusOK) c.Assert(response.StatusCode, Equals, http.StatusOK)
// verify headers // verify headers
verifyHeaders(c, response.Header, metadata.Created, len("hello three"), "application/octet-stream", base64.StdEncoding.EncodeToString([]byte(metadata.Md5))) verifyHeaders(c, response.Header, metadata.Created, len("hello three"), "application/octet-stream", metadata.Md5)
c.Assert(err, IsNil) c.Assert(err, IsNil)
// verify object // verify object
@ -213,7 +214,7 @@ func (s *MySuite) TestHeader(c *C) {
metadata, err := storage.GetObjectMetadata("bucket", "object", "") metadata, err := storage.GetObjectMetadata("bucket", "object", "")
c.Assert(err, IsNil) c.Assert(err, IsNil)
verifyHeaders(c, response.Header, metadata.Created, len("hello world"), "application/octet-stream", base64.StdEncoding.EncodeToString([]byte(metadata.Md5))) verifyHeaders(c, response.Header, metadata.Created, len("hello world"), "application/octet-stream", metadata.Md5)
} }
func (s *MySuite) TestPutBucket(c *C) { func (s *MySuite) TestPutBucket(c *C) {
@ -363,9 +364,11 @@ func (s *MySuite) TestDateFormat(c *C) {
// TODO // TODO
} }
func verifyHeaders(c *C, header http.Header, date time.Time, size int, contentType string, etag string) { func verifyHeaders(c *C, header http.Header, date time.Time, size int, contentType string, md5String string) {
md5Sum, err := hex.DecodeString(md5String)
etag := base64.StdEncoding.EncodeToString(md5Sum)
c.Assert(err, IsNil)
// Verify date // Verify date
c.Log(header)
c.Assert(header.Get("Last-Modified"), Equals, date.Format(time.RFC1123)) c.Assert(header.Get("Last-Modified"), Equals, date.Format(time.RFC1123))
// verify size // verify size

@ -25,6 +25,7 @@ import (
"time" "time"
"encoding/base64" "encoding/base64"
"encoding/hex"
mstorage "github.com/minio-io/minio/pkg/storage" mstorage "github.com/minio-io/minio/pkg/storage"
) )
@ -63,7 +64,8 @@ func writeObjectHeaders(w http.ResponseWriter, metadata mstorage.ObjectMetadata)
lastModified := metadata.Created.Format(time.RFC1123) lastModified := metadata.Created.Format(time.RFC1123)
// common headers // common headers
writeCommonHeaders(w, metadata.ContentType) writeCommonHeaders(w, metadata.ContentType)
w.Header().Set("ETag", base64.StdEncoding.EncodeToString([]byte(metadata.Md5))) md5Bytes, _ := hex.DecodeString(metadata.Md5)
w.Header().Set("ETag", base64.StdEncoding.EncodeToString(md5Bytes))
w.Header().Set("Last-Modified", lastModified) w.Header().Set("Last-Modified", lastModified)
w.Header().Set("Content-Length", strconv.FormatInt(metadata.Size, 10)) w.Header().Set("Content-Length", strconv.FormatInt(metadata.Size, 10))
w.Header().Set("Connection", "close") w.Header().Set("Connection", "close")
@ -74,7 +76,8 @@ func writeRangeObjectHeaders(w http.ResponseWriter, metadata mstorage.ObjectMeta
lastModified := metadata.Created.Format(time.RFC1123) lastModified := metadata.Created.Format(time.RFC1123)
// common headers // common headers
writeCommonHeaders(w, metadata.ContentType) writeCommonHeaders(w, metadata.ContentType)
w.Header().Set("ETag", base64.StdEncoding.EncodeToString([]byte(metadata.Md5))) md5Bytes, _ := hex.DecodeString(metadata.Md5)
w.Header().Set("ETag", base64.StdEncoding.EncodeToString(md5Bytes))
w.Header().Set("Last-Modified", lastModified) w.Header().Set("Last-Modified", lastModified)
w.Header().Set("Content-Range", ra) w.Header().Set("Content-Range", ra)
w.Header().Set("Content-Length", strconv.FormatInt(metadata.Size, 10)) w.Header().Set("Content-Length", strconv.FormatInt(metadata.Size, 10))

@ -90,7 +90,8 @@ func generateObjectsListResult(bucket string, objects []mstorage.ObjectMetadata,
} }
content.Key = object.Key content.Key = object.Key
content.LastModified = object.Created.Format(iso8601Format) content.LastModified = object.Created.Format(iso8601Format)
content.ETag = hex.EncodeToString([]byte(object.Md5)) md5Bytes, _ := hex.DecodeString(object.Md5)
content.ETag = hex.EncodeToString(md5Bytes)
content.Size = object.Size content.Size = object.Size
content.StorageClass = "STANDARD" content.StorageClass = "STANDARD"
content.Owner = owner content.Owner = owner

Loading…
Cancel
Save