[#235] object/head: Support raw flag in service

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-12-08 15:59:01 +03:00 committed by Alex Vanin
parent 1d23483828
commit 397d912e19
5 changed files with 33 additions and 3 deletions

View file

@ -13,7 +13,7 @@ type localHeader struct {
} }
func (h *localHeader) head(ctx context.Context, prm *Prm, handler func(*object.Object)) error { func (h *localHeader) head(ctx context.Context, prm *Prm, handler func(*object.Object)) error {
head, err := engine.Head(h.storage, prm.addr) head, err := engine.HeadRaw(h.storage, prm.addr, prm.raw)
if err != nil { if err != nil {
return errors.Wrapf(err, "(%T) could not get header from local storage", h) return errors.Wrapf(err, "(%T) could not get header from local storage", h)
} }

View file

@ -11,6 +11,8 @@ type Prm struct {
short bool short bool
addr *object.Address addr *object.Address
raw bool
} }
func (p *Prm) WithCommonPrm(v *util.CommonPrm) *Prm { func (p *Prm) WithCommonPrm(v *util.CommonPrm) *Prm {
@ -36,3 +38,11 @@ func (p *Prm) WithAddress(v *object.Address) *Prm {
return p return p
} }
func (p *Prm) WithRaw(v bool) *Prm {
if p != nil {
p.raw = v
}
return p
}

View file

@ -74,7 +74,8 @@ func (h *RemoteHeader) Head(ctx context.Context, prm *RemoteHeadPrm) (*object.Ob
} }
p := new(client.ObjectHeaderParams). p := new(client.ObjectHeaderParams).
WithAddress(prm.commonHeadPrm.addr) WithAddress(prm.commonHeadPrm.addr).
WithRawFlag(prm.commonHeadPrm.raw)
if prm.commonHeadPrm.short { if prm.commonHeadPrm.short {
p = p.WithMainFields() p = p.WithMainFields()

View file

@ -3,6 +3,7 @@ package headsvc
import ( import (
"context" "context"
"github.com/nspcc-dev/neofs-api-go/pkg/object"
objectV2 "github.com/nspcc-dev/neofs-api-go/v2/object" objectV2 "github.com/nspcc-dev/neofs-api-go/v2/object"
headsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/head" headsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/head"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -40,6 +41,12 @@ func (s *Service) Head(ctx context.Context, req *objectV2.HeadRequest) (*objectV
return nil, errors.Wrapf(err, "(%T) could not get object header", s) return nil, errors.Wrapf(err, "(%T) could not get object header", s)
} }
var splitErr *object.SplitInfoError
if errors.As(err, &splitErr) {
return splitInfoResponse(splitErr.SplitInfo()), nil
}
return fromResponse(r, req.GetBody().GetMainOnly()), nil return fromResponse(r, req.GetBody().GetMainOnly()), nil
} }

View file

@ -15,7 +15,8 @@ func toPrm(req *objectV2.HeadRequest) *headsvc.Prm {
object.NewAddressFromV2(body.GetAddress()), object.NewAddressFromV2(body.GetAddress()),
). ).
Short(body.GetMainOnly()). Short(body.GetMainOnly()).
WithCommonPrm(util.CommonPrmFromV2(req)) WithCommonPrm(util.CommonPrmFromV2(req)).
WithRaw(body.GetRaw())
} }
func fromResponse(r *headsvc.Response, short bool) *objectV2.HeadResponse { func fromResponse(r *headsvc.Response, short bool) *objectV2.HeadResponse {
@ -55,3 +56,14 @@ func shortPartFromResponse(r *headsvc.Response) objectV2.GetHeaderPart {
return sh return sh
} }
func splitInfoResponse(info *object.SplitInfo) *objectV2.HeadResponse {
resp := new(objectV2.HeadResponse)
body := new(objectV2.HeadResponseBody)
resp.SetBody(body)
body.SetHeaderPart(info.ToV2())
return resp
}