forked from TrueCloudLab/frostfs-node
[#1194] client: Support request X-headers
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
dd6d7d2d10
commit
b5bdcfc076
3 changed files with 57 additions and 4 deletions
|
@ -30,6 +30,8 @@ type commonPrm struct {
|
|||
tokenBearer *token.BearerToken
|
||||
|
||||
local bool
|
||||
|
||||
xHeaders []*session.XHeader
|
||||
}
|
||||
|
||||
// SetClient sets base client for NeoFS API communication.
|
||||
|
@ -75,8 +77,21 @@ func (x *commonPrm) SetTTL(ttl uint32) {
|
|||
// SetXHeaders sets request X-Headers.
|
||||
//
|
||||
// By default X-Headers will not be attached to the request.
|
||||
func (x *commonPrm) SetXHeaders(_ []*session.XHeader) {
|
||||
// FIXME: (neofs-node#1194) not supported by client
|
||||
func (x *commonPrm) SetXHeaders(hs []*session.XHeader) {
|
||||
x.xHeaders = hs
|
||||
}
|
||||
|
||||
func (x commonPrm) xHeadersPrm() (res []string) {
|
||||
if len(x.xHeaders) > 0 {
|
||||
res = make([]string, len(x.xHeaders)*2)
|
||||
|
||||
for i := range x.xHeaders {
|
||||
res[2*i] = x.xHeaders[i].Key()
|
||||
res[2*i+1] = x.xHeaders[i].Value()
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
type readPrmCommon struct {
|
||||
|
@ -148,6 +163,8 @@ func GetObject(prm GetObjectPrm) (*GetObjectRes, error) {
|
|||
prm.cliPrm.MarkLocal()
|
||||
}
|
||||
|
||||
prm.cliPrm.WithXHeaders(prm.xHeadersPrm()...)
|
||||
|
||||
rdr, err := prm.cli.ObjectGetInit(prm.ctx, prm.cliPrm)
|
||||
if err == nil {
|
||||
return nil, fmt.Errorf("init object reading: %w", err)
|
||||
|
@ -243,6 +260,8 @@ func HeadObject(prm HeadObjectPrm) (*HeadObjectRes, error) {
|
|||
prm.cliPrm.WithBearerToken(*prm.tokenBearer)
|
||||
}
|
||||
|
||||
prm.cliPrm.WithXHeaders(prm.xHeadersPrm()...)
|
||||
|
||||
cliRes, err := prm.cli.ObjectHead(prm.ctx, prm.cliPrm)
|
||||
if err == nil {
|
||||
// pull out an error from status
|
||||
|
@ -335,6 +354,7 @@ func PayloadRange(prm PayloadRangePrm) (*PayloadRangeRes, error) {
|
|||
}
|
||||
|
||||
prm.cliPrm.SetLength(prm.ln)
|
||||
prm.cliPrm.WithXHeaders(prm.xHeadersPrm()...)
|
||||
|
||||
rdr, err := prm.cli.ObjectRangeInit(prm.ctx, prm.cliPrm)
|
||||
if err != nil {
|
||||
|
@ -406,6 +426,8 @@ func PutObject(prm PutObjectPrm) (*PutObjectRes, error) {
|
|||
w.WithBearerToken(*prm.tokenBearer)
|
||||
}
|
||||
|
||||
w.WithXHeaders(prm.xHeadersPrm()...)
|
||||
|
||||
if w.WriteHeader(*prm.obj) {
|
||||
w.WritePayloadChunk(prm.obj.Payload())
|
||||
}
|
||||
|
@ -476,6 +498,8 @@ func SearchObjects(prm SearchObjectsPrm) (*SearchObjectsRes, error) {
|
|||
prm.cliPrm.WithBearerToken(*prm.tokenBearer)
|
||||
}
|
||||
|
||||
prm.cliPrm.WithXHeaders(prm.xHeadersPrm()...)
|
||||
|
||||
rdr, err := prm.cli.ObjectSearchInit(prm.ctx, prm.cliPrm)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("init object searching in client: %w", err)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue