[#13] services/object: Implement Head handlers

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-08-25 19:07:53 +03:00 committed by Alex Vanin
parent 3c773cfa67
commit 881f49814a
2 changed files with 25 additions and 4 deletions

View file

@ -129,8 +129,17 @@ func (s *executorSvc) Put(ctx context.Context) (object.PutObjectStreamer, error)
}, nil }, nil
} }
func (*executorSvc) Head(context.Context, *object.HeadRequest) (*object.HeadResponse, error) { func (s *executorSvc) Head(ctx context.Context, req *object.HeadRequest) (*object.HeadResponse, error) {
panic("implement me") respBody, err := s.exec.Head(ctx, req.GetBody())
if err != nil {
return nil, errors.Wrap(err, "could not execute Head request")
}
resp := new(object.HeadResponse)
resp.SetBody(respBody)
resp.SetMetaHeader(s.metaHeader)
return resp, nil
} }
func (s *searchStreamer) Recv() (*object.SearchResponse, error) { func (s *searchStreamer) Recv() (*object.SearchResponse, error) {

View file

@ -17,6 +17,7 @@ type signService struct {
getSigService *util.UnarySignService getSigService *util.UnarySignService
putService object.Service putService object.Service
rangeSigService *util.UnarySignService rangeSigService *util.UnarySignService
headSigService *util.UnarySignService
} }
type searchStreamSigner struct { type searchStreamSigner struct {
@ -65,6 +66,12 @@ func NewSignService(key *ecdsa.PrivateKey, svc object.Service) object.Service {
return svc.GetRange(ctx, req.(*object.GetRangeRequest)) return svc.GetRange(ctx, req.(*object.GetRangeRequest))
}, },
), ),
headSigService: util.NewUnarySignService(
key,
func(ctx context.Context, req interface{}) (interface{}, error) {
return svc.Head(ctx, req.(*object.HeadRequest))
},
),
} }
} }
@ -126,8 +133,13 @@ func (s *signService) Put(ctx context.Context) (object.PutObjectStreamer, error)
}, nil }, nil
} }
func (s *signService) Head(context.Context, *object.HeadRequest) (*object.HeadResponse, error) { func (s *signService) Head(ctx context.Context, req *object.HeadRequest) (*object.HeadResponse, error) {
panic("implement me") resp, err := s.headSigService.HandleUnaryRequest(ctx, req)
if err != nil {
return nil, err
}
return resp.(*object.HeadResponse), nil
} }
func (s *searchStreamSigner) Recv() (*object.SearchResponse, error) { func (s *searchStreamSigner) Recv() (*object.SearchResponse, error) {