[#188] Improve content-type detector
All checks were successful
/ Builds (push) Successful in 54s
/ Vulncheck (push) Successful in 50s
/ OCI image (push) Successful in 1m28s
/ Lint (push) Successful in 2m3s
/ Tests (push) Successful in 55s

Signed-off-by: Aleksey Kravchenko <al.kravchenko@yadro.com>
This commit is contained in:
Aleksey Kravchenko 2024-12-24 18:42:02 +03:00 committed by Alexey Vanin
parent 1db62f9d95
commit f0c999d9a2
3 changed files with 87 additions and 20 deletions

View file

@ -45,7 +45,11 @@ func (h *Handler) headObject(ctx context.Context, req request, objectAddress oid
}
req.Response.Header.Set(fasthttp.HeaderContentLength, strconv.FormatUint(obj.PayloadSize(), 10))
var contentType string
var (
contentType string
filename string
filepath string
)
for _, attr := range obj.Attributes() {
key := attr.Key()
val := attr.Value()
@ -69,8 +73,15 @@ func (h *Handler) headObject(ctx context.Context, req request, objectAddress oid
req.Response.Header.Set(fasthttp.HeaderLastModified, time.Unix(value, 0).UTC().Format(http.TimeFormat))
case object.AttributeContentType:
contentType = val
case object.AttributeFilePath:
filepath = val
case object.AttributeFileName:
filename = val
}
}
if filename == "" {
filename = filepath
}
idsToResponse(&req.Response, obj)
@ -85,7 +96,7 @@ func (h *Handler) headObject(ctx context.Context, req request, objectAddress oid
}
return h.frostfs.RangeObject(ctx, prmRange)
})
}, filename)
if err != nil && err != io.EOF {
req.handleFrostFSErr(err, start)
return