diff --git a/api/handler/get.go b/api/handler/get.go index e8eb73f..eaef90a 100644 --- a/api/handler/get.go +++ b/api/handler/get.go @@ -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) } } diff --git a/api/handler/list.go b/api/handler/list.go index 9c018e8..f8324b2 100644 --- a/api/handler/list.go +++ b/api/handler/list.go @@ -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{ diff --git a/api/handler/put.go b/api/handler/put.go index cae8a8d..2c054e5 100644 --- a/api/handler/put.go +++ b/api/handler/put.go @@ -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 diff --git a/api/handler/response.go b/api/handler/response.go index fda7f60..42f2e55 100644 --- a/api/handler/response.go +++ b/api/handler/response.go @@ -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. diff --git a/api/headers.go b/api/headers.go index e983a34..b90e403 100644 --- a/api/headers.go +++ b/api/headers.go @@ -2,6 +2,8 @@ package api // Standard S3 HTTP request/response constants. const ( + MetadataPrefix = "X-Amz-Meta-" + LastModified = "Last-Modified" Date = "Date" ETag = "ETag"