[#125] Use the same HEAD, GET headers formation

Signed-off-by: Denis Kirillov <denis@nspcc.ru>
This commit is contained in:
Denis Kirillov 2022-02-15 11:27:51 +03:00 committed by LeL
parent 9d085740e0
commit 2764fabf04
2 changed files with 19 additions and 13 deletions

View file

@ -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 {

View file

@ -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()