aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lu <chrislusf@users.noreply.github.com>2020-06-24 11:33:44 -0700
committerGitHub <noreply@github.com>2020-06-24 11:33:44 -0700
commitc21f4ebfee1455f29d66fb38c55f12ab7dfa232d (patch)
tree9f33e17af043dc3dacdc0e1cf134b76a612f332f
parentfe60db404acc581dcadf400a9fb8a41cecb4bb09 (diff)
parent4eeab2a3793103027767968ca73ae03b2fe51c01 (diff)
downloadseaweedfs-c21f4ebfee1455f29d66fb38c55f12ab7dfa232d.tar.xz
seaweedfs-c21f4ebfee1455f29d66fb38c55f12ab7dfa232d.zip
Merge pull request #1371 from Kimbsen/content_md5_validation
Optional md5 validation of uploads
-rw-r--r--weed/storage/needle/needle_parse_upload.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/weed/storage/needle/needle_parse_upload.go b/weed/storage/needle/needle_parse_upload.go
index dcbfd3819..a2c881f92 100644
--- a/weed/storage/needle/needle_parse_upload.go
+++ b/weed/storage/needle/needle_parse_upload.go
@@ -1,6 +1,7 @@
package needle
import (
+ "crypto/md5"
"fmt"
"io"
"io/ioutil"
@@ -79,6 +80,16 @@ func ParseUpload(r *http.Request, sizeLimit int64) (pu *ParsedUpload, e error) {
}
}
}
+
+ if expectedChecksum := r.Header.Get("Content-MD5"); expectedChecksum != "" {
+ h := md5.New()
+ h.Write(pu.UncompressedData)
+ if receivedChecksum := fmt.Sprintf("%x", h.Sum(nil)); expectedChecksum != receivedChecksum {
+ e = fmt.Errorf("Content-MD5 did not match md5 of file data [%s] != [%s]", expectedChecksum, receivedChecksum)
+ return
+ }
+ }
+
return
}