From 39c29c6d6a05f72a23c9730c3636b2076ea46a34 Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Tue, 15 Feb 2022 12:13:43 +0300 Subject: [PATCH] [#125] Set object ids in a separate function Signed-off-by: Denis Kirillov --- downloader/download.go | 5 ++--- downloader/head.go | 11 ++++++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/downloader/download.go b/downloader/download.go index 03b2729..4964eba 100644 --- a/downloader/download.go +++ b/downloader/download.go @@ -176,9 +176,8 @@ func (r request) receiveFile(clnt pool.Object, objectAddress *object.Address) { contentType = val } } - r.Response.Header.Set(hdrObjectID, obj.ID().String()) - r.Response.Header.Set(hdrOwnerID, obj.OwnerID().String()) - r.Response.Header.Set(hdrContainerID, obj.ContainerID().String()) + + idsToResponse(&r.Response, obj) if len(contentType) == 0 { if readDetector.err != nil { diff --git a/downloader/head.go b/downloader/head.go index 6ec14e3..9093eb1 100644 --- a/downloader/head.go +++ b/downloader/head.go @@ -63,9 +63,8 @@ func (r request) headObject(clnt pool.Object, objectAddress *object.Address) { contentType = val } } - r.Response.Header.Set(hdrObjectID, obj.ID().String()) - r.Response.Header.Set(hdrOwnerID, obj.OwnerID().String()) - r.Response.Header.Set(hdrContainerID, obj.ContainerID().String()) + + idsToResponse(&r.Response, obj) if len(contentType) == 0 { objRange := object.NewRange() @@ -86,6 +85,12 @@ func (r request) headObject(clnt pool.Object, objectAddress *object.Address) { r.SetContentType(contentType) } +func idsToResponse(resp *fasthttp.Response, obj *object.Object) { + resp.Header.Set(hdrObjectID, obj.ID().String()) + resp.Header.Set(hdrOwnerID, obj.OwnerID().String()) + resp.Header.Set(hdrContainerID, obj.ContainerID().String()) +} + // HeadByAddress handles head requests using simple cid/oid format. func (d *Downloader) HeadByAddress(c *fasthttp.RequestCtx) { d.byAddress(c, request.headObject)