From 0e4d07fb06748c618e2649d81be9447e2826dada Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Fri, 26 Aug 2022 13:20:30 +0300 Subject: [PATCH] [#323] client: Remove xheaders length check in a common helper Signed-off-by: Evgenii Stratonikov --- client/common.go | 4 ++++ client/object_delete.go | 4 ---- client/object_get.go | 4 ---- client/object_hash.go | 4 ---- client/object_put.go | 4 ---- client/object_search.go | 4 ---- 6 files changed, 4 insertions(+), 20 deletions(-) diff --git a/client/common.go b/client/common.go index 8ce2f727..c47aafae 100644 --- a/client/common.go +++ b/client/common.go @@ -57,6 +57,10 @@ func writeXHeadersToMeta(xHeaders []string, h *v2session.RequestMetaHeader) { return } + if len(xHeaders)%2 != 0 { + panic("slice of X-Headers with odd length") + } + hs := make([]v2session.XHeader, len(xHeaders)/2) for i := 0; i < len(xHeaders); i += 2 { hs[i].SetKey(xHeaders[i]) diff --git a/client/object_delete.go b/client/object_delete.go index e4feca74..c0a3174a 100644 --- a/client/object_delete.go +++ b/client/object_delete.go @@ -85,10 +85,6 @@ func (x *PrmObjectDelete) UseKey(key ecdsa.PrivateKey) { // // Slice must not be mutated until the operation completes. func (x *PrmObjectDelete) WithXHeaders(hs ...string) { - if len(hs)%2 != 0 { - panic("slice of X-Headers with odd length") - } - writeXHeadersToMeta(hs, &x.meta) } diff --git a/client/object_get.go b/client/object_get.go index 1bc0705b..53aeca99 100644 --- a/client/object_get.go +++ b/client/object_get.go @@ -36,10 +36,6 @@ type prmObjectRead struct { // // Slice must not be mutated until the operation completes. func (x *prmObjectRead) WithXHeaders(hs ...string) { - if len(hs)%2 != 0 { - panic("slice of X-Headers with odd length") - } - writeXHeadersToMeta(hs, &x.meta) } diff --git a/client/object_hash.go b/client/object_hash.go index 03b5f69b..ffcfc518 100644 --- a/client/object_hash.go +++ b/client/object_hash.go @@ -116,10 +116,6 @@ func (x *PrmObjectHash) UseSalt(salt []byte) { // // Slice must not be mutated until the operation completes. func (x *PrmObjectHash) WithXHeaders(hs ...string) { - if len(hs)%2 != 0 { - panic("slice of X-Headers with odd length") - } - writeXHeadersToMeta(hs, &x.meta) } diff --git a/client/object_put.go b/client/object_put.go index 1361992e..a7cb5ca4 100644 --- a/client/object_put.go +++ b/client/object_put.go @@ -102,10 +102,6 @@ func (x *PrmObjectPutInit) MarkLocal() { // // Slice must not be mutated until the operation completes. func (x *PrmObjectPutInit) WithXHeaders(hs ...string) { - if len(hs)%2 != 0 { - panic("slice of X-Headers with odd length") - } - writeXHeadersToMeta(hs, &x.meta) } diff --git a/client/object_search.go b/client/object_search.go index 1ab93962..cf5f2c1e 100644 --- a/client/object_search.go +++ b/client/object_search.go @@ -67,10 +67,6 @@ func (x *PrmObjectSearch) WithBearerToken(t bearer.Token) { // // Slice must not be mutated until the operation completes. func (x *PrmObjectSearch) WithXHeaders(hs ...string) { - if len(hs)%2 != 0 { - panic("slice of X-Headers with odd length") - } - writeXHeadersToMeta(hs, &x.meta) }