Switching from base64 to hex for etag

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

@ -32,8 +32,6 @@ import (
mstorage "github.com/minio-io/minio/pkg/storage" mstorage "github.com/minio-io/minio/pkg/storage"
"github.com/minio-io/minio/pkg/storage/memory" "github.com/minio-io/minio/pkg/storage/memory"
"encoding/base64"
"encoding/hex"
. "gopkg.in/check.v1" . "gopkg.in/check.v1"
) )
@ -364,10 +362,7 @@ func (s *MySuite) TestDateFormat(c *C) {
// TODO // TODO
} }
func verifyHeaders(c *C, header http.Header, date time.Time, size int, contentType string, md5String string) { func verifyHeaders(c *C, header http.Header, date time.Time, size int, contentType string, etag string) {
md5Sum, err := hex.DecodeString(md5String)
etag := base64.StdEncoding.EncodeToString(md5Sum)
c.Assert(err, IsNil)
// Verify date // Verify date
c.Assert(header.Get("Last-Modified"), Equals, date.Format(time.RFC1123)) c.Assert(header.Get("Last-Modified"), Equals, date.Format(time.RFC1123))

@ -24,8 +24,6 @@ import (
"strconv" "strconv"
"time" "time"
"encoding/base64"
"encoding/hex"
mstorage "github.com/minio-io/minio/pkg/storage" mstorage "github.com/minio-io/minio/pkg/storage"
) )
@ -64,8 +62,7 @@ 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)
md5Bytes, _ := hex.DecodeString(metadata.Md5) w.Header().Set("ETag", 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")
@ -76,8 +73,7 @@ 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)
md5Bytes, _ := hex.DecodeString(metadata.Md5) w.Header().Set("ETag", 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))

@ -19,7 +19,6 @@ package minioapi
import ( import (
"sort" "sort"
"encoding/hex"
mstorage "github.com/minio-io/minio/pkg/storage" mstorage "github.com/minio-io/minio/pkg/storage"
) )
@ -90,8 +89,7 @@ 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)
md5Bytes, _ := hex.DecodeString(object.Md5) content.ETag = 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