etag: add FromContentMD5 to parse content-md5 as ETag (#11688)

This commit adds the `FromContentMD5` function to
parse a client-provided content-md5 as ETag.

Further, it also adds multipart ETag computation
for future needs.
This commit is contained in:
Andreas Auernhammer
2021-03-03 21:58:28 +01:00
committed by GitHub
parent 2c198ae7b6
commit f14cc6c943
5 changed files with 137 additions and 28 deletions

View File

@@ -20,7 +20,6 @@ import (
"bytes"
"context"
"crypto/tls"
"encoding/base64"
"encoding/json"
"encoding/xml"
"errors"
@@ -143,18 +142,6 @@ func xmlDecoder(body io.Reader, v interface{}, size int64) error {
return d.Decode(v)
}
// checkValidMD5 - verify if valid md5, returns md5 in bytes.
func checkValidMD5(h http.Header) ([]byte, error) {
md5B64, ok := h[xhttp.ContentMD5]
if ok {
if md5B64[0] == "" {
return nil, fmt.Errorf("Content-Md5 header set to empty value")
}
return base64.StdEncoding.Strict().DecodeString(md5B64[0])
}
return []byte{}, nil
}
// hasContentMD5 returns true if Content-MD5 header is set.
func hasContentMD5(h http.Header) bool {
_, ok := h[xhttp.ContentMD5]