[#285] services/object: Add X-Headers to client call options

Forward request X-headers to client calls during internal processing of
Object operations on the node.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-12-28 18:55:16 +03:00 committed by Alex Vanin
parent 0855dec9c2
commit c69f867af1

View file

@ -3,6 +3,7 @@ package util
import ( import (
"crypto/ecdsa" "crypto/ecdsa"
"github.com/nspcc-dev/neofs-api-go/pkg"
"github.com/nspcc-dev/neofs-api-go/pkg/client" "github.com/nspcc-dev/neofs-api-go/pkg/client"
"github.com/nspcc-dev/neofs-api-go/pkg/token" "github.com/nspcc-dev/neofs-api-go/pkg/token"
"github.com/nspcc-dev/neofs-api-go/v2/session" "github.com/nspcc-dev/neofs-api-go/v2/session"
@ -109,11 +110,15 @@ func CommonPrmFromV2(req interface {
}) *CommonPrm { }) *CommonPrm {
meta := req.GetMetaHeader() meta := req.GetMetaHeader()
xHdrs := meta.GetXHeaders()
const staticOptNum = 3
prm := &CommonPrm{ prm := &CommonPrm{
local: meta.GetTTL() <= 1, // FIXME: use constant local: meta.GetTTL() <= 1, // FIXME: use constant
token: nil, token: nil,
bearer: nil, bearer: nil,
callOpts: make([]client.CallOption, 0, 3), callOpts: make([]client.CallOption, 0, staticOptNum+len(xHdrs)),
} }
prm.callOpts = append(prm.callOpts, client.WithTTL(meta.GetTTL()-1)) prm.callOpts = append(prm.callOpts, client.WithTTL(meta.GetTTL()-1))
@ -128,5 +133,13 @@ func CommonPrmFromV2(req interface {
prm.callOpts = append(prm.callOpts, client.WithBearer(prm.bearer)) prm.callOpts = append(prm.callOpts, client.WithBearer(prm.bearer))
} }
for i := range xHdrs {
prm.callOpts = append(prm.callOpts,
client.WithXHeader(
pkg.NewXHeaderFromV2(xHdrs[i]),
),
)
}
return prm return prm
} }