aboutsummaryrefslogtreecommitdiff
path: root/weed
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2018-11-08 21:41:02 -0800
committerChris Lu <chris.lu@gmail.com>2018-11-08 21:41:02 -0800
commita4ceb051a7aa195ba9e16995602a615b23f4b746 (patch)
tree3667a1e364dbcc07d9dddae804e3974d61b2d5d8 /weed
parent6e53c38c2fc8dd7e0bc0bcd1909588bfe532edf8 (diff)
downloadseaweedfs-a4ceb051a7aa195ba9e16995602a615b23f4b746.tar.xz
seaweedfs-a4ceb051a7aa195ba9e16995602a615b23f4b746.zip
use MD5 for ETag to be consistent with Amazon S3
Diffstat (limited to 'weed')
-rw-r--r--weed/s3api/s3api_object_handlers.go10
-rw-r--r--weed/server/volume_server_handlers_read.go6
-rw-r--r--weed/storage/crc.go13
3 files changed, 24 insertions, 5 deletions
diff --git a/weed/s3api/s3api_object_handlers.go b/weed/s3api/s3api_object_handlers.go
index 93816c7ee..d9cb0c072 100644
--- a/weed/s3api/s3api_object_handlers.go
+++ b/weed/s3api/s3api_object_handlers.go
@@ -63,6 +63,7 @@ func (s3a *S3ApiServer) GetObjectHandler(w http.ResponseWriter, r *http.Request)
vars := mux.Vars(r)
bucket := vars["bucket"]
+ object := getObject(vars)
if strings.HasSuffix(r.URL.Path, "/") {
writeErrorResponse(w, ErrNotImplemented, r.URL)
@@ -70,7 +71,7 @@ func (s3a *S3ApiServer) GetObjectHandler(w http.ResponseWriter, r *http.Request)
}
destUrl := fmt.Sprintf("http://%s%s/%s%s",
- s3a.option.Filer, s3a.option.BucketsPath, bucket, r.RequestURI)
+ s3a.option.Filer, s3a.option.BucketsPath, bucket, object)
s3a.proxyToFiler(w, r, destUrl, passThroghResponse)
@@ -80,9 +81,10 @@ func (s3a *S3ApiServer) HeadObjectHandler(w http.ResponseWriter, r *http.Request
vars := mux.Vars(r)
bucket := vars["bucket"]
+ object := getObject(vars)
destUrl := fmt.Sprintf("http://%s%s/%s%s",
- s3a.option.Filer, s3a.option.BucketsPath, bucket, r.RequestURI)
+ s3a.option.Filer, s3a.option.BucketsPath, bucket, object)
s3a.proxyToFiler(w, r, destUrl, passThroghResponse)
@@ -92,9 +94,10 @@ func (s3a *S3ApiServer) DeleteObjectHandler(w http.ResponseWriter, r *http.Reque
vars := mux.Vars(r)
bucket := vars["bucket"]
+ object := getObject(vars)
destUrl := fmt.Sprintf("http://%s%s/%s%s",
- s3a.option.Filer, s3a.option.BucketsPath, bucket, r.RequestURI)
+ s3a.option.Filer, s3a.option.BucketsPath, bucket, object)
s3a.proxyToFiler(w, r, destUrl, func(proxyResonse *http.Response, w http.ResponseWriter) {
for k, v := range proxyResonse.Header {
@@ -125,6 +128,7 @@ func (s3a *S3ApiServer) proxyToFiler(w http.ResponseWriter, r *http.Request, des
proxyReq.Header.Set("Host", s3a.option.Filer)
proxyReq.Header.Set("X-Forwarded-For", r.RemoteAddr)
+ proxyReq.Header.Set("Etag-MD5", "True")
for header, values := range r.Header {
for _, value := range values {
diff --git a/weed/server/volume_server_handlers_read.go b/weed/server/volume_server_handlers_read.go
index 4da13883e..aa6dff087 100644
--- a/weed/server/volume_server_handlers_read.go
+++ b/weed/server/volume_server_handlers_read.go
@@ -92,7 +92,11 @@ func (vs *VolumeServer) GetOrHeadHandler(w http.ResponseWriter, r *http.Request)
w.WriteHeader(http.StatusNotModified)
return
}
- setEtag(w, n.Etag())
+ if r.Header.Get("ETag-MD5") == "True" {
+ setEtag(w, n.MD5())
+ }else{
+ setEtag(w, n.Etag())
+ }
if n.HasPairs() {
pairMap := make(map[string]string)
diff --git a/weed/storage/crc.go b/weed/storage/crc.go
index e31e0f815..df44d1679 100644
--- a/weed/storage/crc.go
+++ b/weed/storage/crc.go
@@ -2,8 +2,9 @@ package storage
import (
"fmt"
- "github.com/klauspost/crc32"
+ "crypto/md5"
+ "github.com/klauspost/crc32"
"github.com/chrislusf/seaweedfs/weed/util"
)
@@ -28,3 +29,13 @@ func (n *Needle) Etag() string {
util.Uint32toBytes(bits, uint32(n.Checksum))
return fmt.Sprintf("%x", bits)
}
+
+func (n *Needle) MD5() string {
+
+ hash := md5.New()
+
+ hash.Write(n.Data)
+
+ return fmt.Sprintf("%x", hash.Sum(nil))
+
+}