Merge pull request #309 from fkautz/pr_out_performing_etag_off_of_bytes_rather_than_md5_string
This commit is contained in:
commit
cda13750f7
3 changed files with 18 additions and 11 deletions
|
@ -33,6 +33,7 @@ import (
|
|||
"github.com/minio-io/minio/pkg/storage/memory"
|
||||
|
||||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
. "gopkg.in/check.v1"
|
||||
)
|
||||
|
||||
|
@ -74,7 +75,7 @@ func (s *MySuite) TestEmptyObject(c *C) {
|
|||
|
||||
metadata, err := storage.GetObjectMetadata("bucket", "object", "")
|
||||
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
|
||||
}
|
||||
|
@ -99,7 +100,7 @@ func (s *MySuite) TestObject(c *C) {
|
|||
|
||||
metadata, err := storage.GetObjectMetadata("bucket", "object", "")
|
||||
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) {
|
||||
|
@ -135,7 +136,7 @@ func (s *MySuite) TestMultipleObjects(c *C) {
|
|||
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
||||
|
||||
// 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)
|
||||
|
||||
// verify response data
|
||||
|
@ -154,7 +155,7 @@ func (s *MySuite) TestMultipleObjects(c *C) {
|
|||
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
||||
|
||||
// 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)
|
||||
|
||||
// verify response data
|
||||
|
@ -173,7 +174,7 @@ func (s *MySuite) TestMultipleObjects(c *C) {
|
|||
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
||||
|
||||
// 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)
|
||||
|
||||
// verify object
|
||||
|
@ -213,7 +214,7 @@ func (s *MySuite) TestHeader(c *C) {
|
|||
|
||||
metadata, err := storage.GetObjectMetadata("bucket", "object", "")
|
||||
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) {
|
||||
|
@ -363,9 +364,11 @@ func (s *MySuite) TestDateFormat(c *C) {
|
|||
// 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
|
||||
c.Log(header)
|
||||
c.Assert(header.Get("Last-Modified"), Equals, date.Format(time.RFC1123))
|
||||
|
||||
// verify size
|
||||
|
|
|
@ -25,6 +25,7 @@ import (
|
|||
"time"
|
||||
|
||||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
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)
|
||||
// common headers
|
||||
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("Content-Length", strconv.FormatInt(metadata.Size, 10))
|
||||
w.Header().Set("Connection", "close")
|
||||
|
@ -74,7 +76,8 @@ func writeRangeObjectHeaders(w http.ResponseWriter, metadata mstorage.ObjectMeta
|
|||
lastModified := metadata.Created.Format(time.RFC1123)
|
||||
// common headers
|
||||
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("Content-Range", ra)
|
||||
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.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.StorageClass = "STANDARD"
|
||||
content.Owner = owner
|
||||
|
|
Loading…
Reference in a new issue