diff --git a/api/handler/put.go b/api/handler/put.go index cae8a8df2..2c054e5fe 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/headers.go b/api/headers.go index e983a3424..b90e4035d 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"