[#117] Add mocked handler for tests
All checks were successful
/ DCO (pull_request) Successful in 1m22s
/ Builds (1.21) (pull_request) Successful in 1m58s
/ Builds (1.22) (pull_request) Successful in 1m53s
/ Vulncheck (pull_request) Successful in 3m32s
/ Lint (pull_request) Successful in 5m1s
/ Tests (1.21) (pull_request) Successful in 2m38s
/ Tests (1.22) (pull_request) Successful in 3m4s

Signed-off-by: Denis Kirillov <d.kirillov@yadro.com>
This commit is contained in:
Denis Kirillov 2024-06-17 17:56:43 +03:00
parent 826dd0cdbe
commit 3741e3b003
12 changed files with 1005 additions and 113 deletions

View file

@ -11,7 +11,6 @@ import (
"git.frostfs.info/TrueCloudLab/frostfs-http-gw/utils"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/pool"
"github.com/valyala/fasthttp"
"go.uber.org/zap"
)
@ -30,21 +29,23 @@ func (h *Handler) headObject(ctx context.Context, req request, objectAddress oid
btoken := bearerToken(ctx)
var prm pool.PrmObjectHead
prm.SetAddress(objectAddress)
if btoken != nil {
prm.UseBearer(*btoken)
prm := PrmObjectRead{
PrmAuth: PrmAuth{
BearerToken: btoken,
},
Address: objectAddress,
WithHeader: true,
}
obj, err := h.pool.HeadObject(ctx, prm)
obj, err := h.frostfs.ReadObject(ctx, prm)
if err != nil {
req.handleFrostFSErr(err, start)
return
}
req.Response.Header.Set(fasthttp.HeaderContentLength, strconv.FormatUint(obj.PayloadSize(), 10))
req.Response.Header.Set(fasthttp.HeaderContentLength, strconv.FormatUint(obj.Head.PayloadSize(), 10))
var contentType string
for _, attr := range obj.Attributes() {
for _, attr := range obj.Head.Attributes() {
key := attr.Key()
val := attr.Value()
if !isValidToken(key) || !isValidValue(val) {
@ -70,22 +71,24 @@ func (h *Handler) headObject(ctx context.Context, req request, objectAddress oid
}
}
idsToResponse(&req.Response, &obj)
idsToResponse(&req.Response, obj.Head)
if len(contentType) == 0 {
contentType, _, err = readContentType(obj.PayloadSize(), func(sz uint64) (io.Reader, error) {
var prmRange pool.PrmObjectRange
prmRange.SetAddress(objectAddress)
prmRange.SetLength(sz)
if btoken != nil {
prmRange.UseBearer(*btoken)
contentType, _, err = readContentType(obj.Head.PayloadSize(), func(sz uint64) (io.Reader, error) {
prmRange := PrmObjectRead{
PrmAuth: PrmAuth{
BearerToken: btoken,
},
Address: objectAddress,
WithPayload: true,
PayloadRange: [2]uint64{0, sz},
}
resObj, err := h.pool.ObjectRange(ctx, prmRange)
resObj, err := h.frostfs.ReadObject(ctx, prmRange)
if err != nil {
return nil, err
}
return &resObj, nil
return resObj.Payload, nil
})
if err != nil && err != io.EOF {
req.handleFrostFSErr(err, start)