From 2764fabf045b4d3b940c6095c89d3282da186e24 Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Tue, 15 Feb 2022 11:27:51 +0300 Subject: [PATCH] [#125] Use the same HEAD, GET headers formation Signed-off-by: Denis Kirillov --- downloader/download.go | 16 ++++++++-------- downloader/head.go | 16 +++++++++++----- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/downloader/download.go b/downloader/download.go index 93aa020..03b2729 100644 --- a/downloader/download.go +++ b/downloader/download.go @@ -146,7 +146,7 @@ func (r request) receiveFile(clnt pool.Object, objectAddress *object.Address) { dis = "attachment" } r.Response.SetBodyStream(readDetector.MultiReader(), int(obj.PayloadSize())) - r.Response.Header.Set("Content-Length", strconv.FormatUint(obj.PayloadSize(), 10)) + r.Response.Header.Set(fasthttp.HeaderContentLength, strconv.FormatUint(obj.PayloadSize(), 10)) var contentType string for _, attr := range obj.Attributes() { key := attr.Key() @@ -170,15 +170,15 @@ func (r request) receiveFile(clnt pool.Object, objectAddress *object.Address) { zap.Error(err)) continue } - r.Response.Header.Set("Last-Modified", + r.Response.Header.Set(fasthttp.HeaderLastModified, time.Unix(value, 0).UTC().Format(http.TimeFormat)) case object.AttributeContentType: contentType = val } } - r.Response.Header.Set("X-Object-Id", obj.ID().String()) - r.Response.Header.Set("X-Owner-Id", obj.OwnerID().String()) - r.Response.Header.Set("X-Container-Id", obj.ContainerID().String()) + r.Response.Header.Set(hdrObjectID, obj.ID().String()) + r.Response.Header.Set(hdrOwnerID, obj.OwnerID().String()) + r.Response.Header.Set(hdrContainerID, obj.ContainerID().String()) if len(contentType) == 0 { if readDetector.err != nil { @@ -191,7 +191,7 @@ func (r request) receiveFile(clnt pool.Object, objectAddress *object.Address) { } r.SetContentType(contentType) - r.Response.Header.Set("Content-Disposition", dis+"; filename="+path.Base(filename)) + r.Response.Header.Set(fasthttp.HeaderContentDisposition, dis+"; filename="+path.Base(filename)) } // systemBackwardTranslator is used to convert headers looking like '__NEOFS__ATTR_NAME' to 'Neofs-Attr-Name'. @@ -414,8 +414,8 @@ func (d *Downloader) DownloadZipped(c *fasthttp.RequestCtx) { return } - c.Response.Header.Set("Content-Type", "application/zip") - c.Response.Header.Set("Content-Disposition", "attachment; filename=\"archive.zip\"") + c.Response.Header.Set(fasthttp.HeaderContentType, "application/zip") + c.Response.Header.Set(fasthttp.HeaderContentDisposition, "attachment; filename=\"archive.zip\"") c.Response.SetStatusCode(http.StatusOK) if err = d.streamFiles(c, containerID, ids); err != nil { diff --git a/downloader/head.go b/downloader/head.go index 8e113e6..6ec14e3 100644 --- a/downloader/head.go +++ b/downloader/head.go @@ -17,6 +17,12 @@ import ( const sizeToDetectType = 512 +const ( + hdrObjectID = "X-Object-Id" + hdrOwnerID = "X-Owner-Id" + hdrContainerID = "X-Container-Id" +) + func (r request) headObject(clnt pool.Object, objectAddress *object.Address) { var start = time.Now() if err := tokens.StoreBearerToken(r.RequestCtx); err != nil { @@ -33,7 +39,7 @@ func (r request) headObject(clnt pool.Object, objectAddress *object.Address) { return } - r.Response.Header.Set("Content-Length", strconv.FormatUint(obj.PayloadSize(), 10)) + r.Response.Header.Set(fasthttp.HeaderContentLength, strconv.FormatUint(obj.PayloadSize(), 10)) var contentType string for _, attr := range obj.Attributes() { key := attr.Key() @@ -52,14 +58,14 @@ func (r request) headObject(clnt pool.Object, objectAddress *object.Address) { zap.Error(err)) continue } - r.Response.Header.Set("Last-Modified", time.Unix(value, 0).UTC().Format(http.TimeFormat)) + r.Response.Header.Set(fasthttp.HeaderLastModified, time.Unix(value, 0).UTC().Format(http.TimeFormat)) case object.AttributeContentType: contentType = val } } - r.Response.Header.Set("x-object-id", obj.ID().String()) - r.Response.Header.Set("x-owner-id", obj.OwnerID().String()) - r.Response.Header.Set("x-container-id", obj.ContainerID().String()) + r.Response.Header.Set(hdrObjectID, obj.ID().String()) + r.Response.Header.Set(hdrOwnerID, obj.OwnerID().String()) + r.Response.Header.Set(hdrContainerID, obj.ContainerID().String()) if len(contentType) == 0 { objRange := object.NewRange()