1
0
Fork 0
mirror of https://github.com/chrislusf/seaweedfs synced 2024-06-29 13:50:10 +02:00

Merge pull request #1371 from Kimbsen/content_md5_validation

Optional md5 validation of uploads
This commit is contained in:
Chris Lu 2020-06-24 11:33:44 -07:00 committed by GitHub
commit c21f4ebfee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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
}