mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-10-21 04:57:24 +08:00
volume: report Content-MD5 in response header
This commit is contained in:
@@ -48,7 +48,7 @@ func (n *Needle) String() (str string) {
|
||||
return
|
||||
}
|
||||
|
||||
func CreateNeedleFromRequest(r *http.Request, fixJpgOrientation bool, sizeLimit int64) (n *Needle, originalSize int, e error) {
|
||||
func CreateNeedleFromRequest(r *http.Request, fixJpgOrientation bool, sizeLimit int64) (n *Needle, originalSize int, md5 string, e error) {
|
||||
n = new(Needle)
|
||||
pu, e := ParseUpload(r, sizeLimit)
|
||||
if e != nil {
|
||||
|
@@ -29,6 +29,7 @@ type ParsedUpload struct {
|
||||
Ttl *TTL
|
||||
IsChunkedFile bool
|
||||
UncompressedData []byte
|
||||
ContentMd5 string
|
||||
}
|
||||
|
||||
func ParseUpload(r *http.Request, sizeLimit int64) (pu *ParsedUpload, e error) {
|
||||
@@ -83,11 +84,13 @@ func ParseUpload(r *http.Request, sizeLimit int64) (pu *ParsedUpload, e error) {
|
||||
}
|
||||
}
|
||||
|
||||
// md5
|
||||
h := md5.New()
|
||||
h.Write(pu.UncompressedData)
|
||||
pu.ContentMd5 = base64.StdEncoding.EncodeToString(h.Sum(nil))
|
||||
if expectedChecksum := r.Header.Get("Content-MD5"); expectedChecksum != "" {
|
||||
h := md5.New()
|
||||
h.Write(pu.UncompressedData)
|
||||
if receivedChecksum := base64.StdEncoding.EncodeToString(h.Sum(nil)); expectedChecksum != receivedChecksum {
|
||||
e = fmt.Errorf("Content-MD5 did not match md5 of file data [%s] != [%s]", expectedChecksum, receivedChecksum)
|
||||
if expectedChecksum != pu.ContentMd5 {
|
||||
e = fmt.Errorf("Content-MD5 did not match md5 of file data [%s] != [%s]", expectedChecksum, pu.ContentMd5)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user