forked from TrueCloudLab/frostfs-s3-gw
[#93] Object ETag support
Signed-off-by: Denis Kirillov <denis@nspcc.ru>
This commit is contained in:
parent
b565045649
commit
a6ec27b40d
6 changed files with 26 additions and 12 deletions
|
@ -81,7 +81,7 @@ func (h *handler) CopyObjectHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}, r.URL)
|
}, r.URL)
|
||||||
|
|
||||||
return
|
return
|
||||||
} else if err = api.EncodeToResponse(w, &CopyObjectResponse{LastModified: inf.Created.Format(time.RFC3339)}); err != nil {
|
} else if err = api.EncodeToResponse(w, &CopyObjectResponse{LastModified: inf.Created.Format(time.RFC3339), ETag: inf.HashSum}); err != nil {
|
||||||
h.log.Error("something went wrong",
|
h.log.Error("something went wrong",
|
||||||
zap.String("request_id", rid),
|
zap.String("request_id", rid),
|
||||||
zap.String("dst_bucket_name", bkt),
|
zap.String("dst_bucket_name", bkt),
|
||||||
|
|
|
@ -109,9 +109,10 @@ func fetchRangeHeader(headers http.Header, fullSize uint64) (*layer.RangeParams,
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeHeaders(h http.Header, info *layer.ObjectInfo) {
|
func writeHeaders(h http.Header, info *layer.ObjectInfo) {
|
||||||
h.Set("Content-Type", info.ContentType)
|
h.Set(api.ContentType, info.ContentType)
|
||||||
h.Set("Last-Modified", info.Created.Format(http.TimeFormat))
|
h.Set(api.LastModified, info.Created.Format(http.TimeFormat))
|
||||||
h.Set("Content-Length", strconv.FormatInt(info.Size, 10))
|
h.Set(api.ContentLength, strconv.FormatInt(info.Size, 10))
|
||||||
|
h.Set(api.ETag, info.HashSum)
|
||||||
|
|
||||||
for key, val := range info.Headers {
|
for key, val := range info.Headers {
|
||||||
h.Set("X-"+key, val)
|
h.Set("X-"+key, val)
|
||||||
|
|
|
@ -196,7 +196,7 @@ func encodeV1(arg *listObjectsArgs, list *layer.ListObjectsInfo) *ListObjectsRes
|
||||||
DisplayName: obj.Owner.String(),
|
DisplayName: obj.Owner.String(),
|
||||||
},
|
},
|
||||||
|
|
||||||
// ETag: "",
|
ETag: obj.HashSum,
|
||||||
// StorageClass: "",
|
// StorageClass: "",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -259,7 +259,7 @@ func encodeV2(arg *listObjectsArgs, list *layer.ListObjectsInfo) *ListObjectsV2R
|
||||||
DisplayName: obj.Owner.String(),
|
DisplayName: obj.Owner.String(),
|
||||||
},
|
},
|
||||||
|
|
||||||
// ETag: "",
|
ETag: obj.HashSum,
|
||||||
// StorageClass: "",
|
// StorageClass: "",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,11 +24,12 @@ const (
|
||||||
|
|
||||||
func (h *handler) PutObjectHandler(w http.ResponseWriter, r *http.Request) {
|
func (h *handler) PutObjectHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
req = mux.Vars(r)
|
info *layer.ObjectInfo
|
||||||
bkt = req["bucket"]
|
req = mux.Vars(r)
|
||||||
obj = req["object"]
|
bkt = req["bucket"]
|
||||||
rid = api.GetRequestID(r.Context())
|
obj = req["object"]
|
||||||
|
rid = api.GetRequestID(r.Context())
|
||||||
)
|
)
|
||||||
|
|
||||||
if _, err := h.obj.GetBucketInfo(r.Context(), bkt); err != nil {
|
if _, err := h.obj.GetBucketInfo(r.Context(), bkt); err != nil {
|
||||||
|
@ -53,7 +54,7 @@ func (h *handler) PutObjectHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
Size: r.ContentLength,
|
Size: r.ContentLength,
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err = h.obj.PutObject(r.Context(), params); err != nil {
|
if info, err = h.obj.PutObject(r.Context(), params); err != nil {
|
||||||
h.log.Error("could not upload object",
|
h.log.Error("could not upload object",
|
||||||
zap.String("request_id", rid),
|
zap.String("request_id", rid),
|
||||||
zap.String("bucket_name", bkt),
|
zap.String("bucket_name", bkt),
|
||||||
|
@ -69,6 +70,7 @@ func (h *handler) PutObjectHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
w.Header().Set(api.ETag, info.HashSum)
|
||||||
api.WriteSuccessResponseHeadersOnly(w)
|
api.WriteSuccessResponseHeadersOnly(w)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -142,6 +142,14 @@ func (n *layer) objectPut(ctx context.Context, p *PutObjectParams) (*ObjectInfo,
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addr := object.NewAddress()
|
||||||
|
addr.SetObjectID(oid)
|
||||||
|
addr.SetContainerID(bkt.CID)
|
||||||
|
meta, err := n.objectHead(ctx, addr)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
return &ObjectInfo{
|
return &ObjectInfo{
|
||||||
id: oid,
|
id: oid,
|
||||||
|
|
||||||
|
@ -152,6 +160,7 @@ func (n *layer) objectPut(ctx context.Context, p *PutObjectParams) (*ObjectInfo,
|
||||||
Created: time.Now(),
|
Created: time.Now(),
|
||||||
Headers: p.Header,
|
Headers: p.Header,
|
||||||
ContentType: r.contentType,
|
ContentType: r.contentType,
|
||||||
|
HashSum: meta.PayloadChecksum().String(),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@ type (
|
||||||
Size int64
|
Size int64
|
||||||
ContentType string
|
ContentType string
|
||||||
Created time.Time
|
Created time.Time
|
||||||
|
HashSum string
|
||||||
Owner *owner.ID
|
Owner *owner.ID
|
||||||
Headers map[string]string
|
Headers map[string]string
|
||||||
}
|
}
|
||||||
|
@ -119,6 +120,7 @@ func objectInfoFromMeta(bkt *BucketInfo, meta *object.Object, prefix, delimiter
|
||||||
Headers: userHeaders,
|
Headers: userHeaders,
|
||||||
Owner: meta.OwnerID(),
|
Owner: meta.OwnerID(),
|
||||||
Size: size,
|
Size: size,
|
||||||
|
HashSum: meta.PayloadChecksum().String(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue