Merge pull request #148 from masterSplinter01/bugfix/131-add-metadata

Fix metadata
This commit is contained in:
Alex Vanin 2021-07-09 17:20:59 +03:00 committed by GitHub
commit 1f656aac23
5 changed files with 17 additions and 6 deletions

View file

@ -69,7 +69,7 @@ func writeHeaders(h http.Header, info *layer.ObjectInfo) {
h.Set(api.ETag, info.HashSum)
for key, val := range info.Headers {
h.Set("X-"+key, val)
h.Set(api.MetadataPrefix+key, val)
}
}

View file

@ -202,7 +202,6 @@ func encodeV1(arg *listObjectsArgs, list *layer.ListObjectsInfo) *ListObjectsRes
res.Contents = append(res.Contents, Object{
Key: obj.Name,
Size: obj.Size,
UserMetadata: obj.Headers,
LastModified: obj.Created.Format(time.RFC3339),
Owner: Owner{
@ -265,7 +264,6 @@ func encodeV2(arg *listObjectsArgs, list *layer.ListObjectsInfo) *ListObjectsV2R
res.Contents = append(res.Contents, Object{
Key: obj.Name,
Size: obj.Size,
UserMetadata: obj.Headers,
LastModified: obj.Created.Format(time.RFC3339),
Owner: Owner{

View file

@ -47,11 +47,14 @@ func (h *handler) PutObjectHandler(w http.ResponseWriter, r *http.Request) {
return
}
metadata := parseMetadata(r)
params := &layer.PutObjectParams{
Bucket: bkt,
Object: obj,
Reader: r.Body,
Size: r.ContentLength,
Header: metadata,
}
if info, err = h.obj.PutObject(r.Context(), params); err != nil {
@ -74,6 +77,17 @@ func (h *handler) PutObjectHandler(w http.ResponseWriter, r *http.Request) {
api.WriteSuccessResponseHeadersOnly(w)
}
func parseMetadata(r *http.Request) map[string]string {
res := make(map[string]string)
for k, v := range r.Header {
if strings.HasPrefix(k, api.MetadataPrefix) {
key := strings.TrimPrefix(k, api.MetadataPrefix)
res[key] = v[0]
}
}
return res
}
func (h *handler) CreateBucketHandler(w http.ResponseWriter, r *http.Request) {
var (
err error

View file

@ -104,9 +104,6 @@ type Object struct {
// The class of storage used to store the object.
StorageClass string `xml:"StorageClass,omitempty"`
// UserMetadata user-defined metadata
UserMetadata StringMap `xml:"UserMetadata,omitempty"`
}
// ObjectVersionResponse container for object version in the response of ListBucketObjectVersionsHandler.

View file

@ -2,6 +2,8 @@ package api
// Standard S3 HTTP request/response constants.
const (
MetadataPrefix = "X-Amz-Meta-"
LastModified = "Last-Modified"
Date = "Date"
ETag = "ETag"