[#111] Fix expiration epoch headers
Signed-off-by: Angira Kekteeva <kira@nspcc.ru>
This commit is contained in:
parent
dbbc9e05cf
commit
d6dd244756
2 changed files with 46 additions and 0 deletions
|
@ -153,6 +153,9 @@ func (r request) receiveFile(clnt pool.Object, objectAddress *object.Address) {
|
|||
if !isValidToken(key) || !isValidValue(val) {
|
||||
continue
|
||||
}
|
||||
if strings.HasPrefix(key, utils.SystemAttributePrefix) {
|
||||
key = systemBackwardTranslator(key)
|
||||
}
|
||||
r.Response.Header.Set(utils.UserAttributeHeaderPrefix+key, val)
|
||||
switch key {
|
||||
case object.AttributeFileName:
|
||||
|
@ -190,6 +193,26 @@ func (r request) receiveFile(clnt pool.Object, objectAddress *object.Address) {
|
|||
r.Response.Header.Set("Content-Disposition", dis+"; filename="+path.Base(filename))
|
||||
}
|
||||
|
||||
// systemBackwardTranslator is used to convert headers looking like '__NEOFS__ATTR_NAME' to 'Neofs-Attr-Name'.
|
||||
func systemBackwardTranslator(key string) string {
|
||||
// trim specified prefix '__NEOFS__'
|
||||
key = strings.TrimPrefix(key, utils.SystemAttributePrefix)
|
||||
|
||||
var res strings.Builder
|
||||
res.WriteString("Neofs-")
|
||||
|
||||
strs := strings.Split(key, "_")
|
||||
for i, s := range strs {
|
||||
s = strings.Title(strings.ToLower(s))
|
||||
res.WriteString(s)
|
||||
if i != len(strs)-1 {
|
||||
res.WriteString("-")
|
||||
}
|
||||
}
|
||||
|
||||
return res.String()
|
||||
}
|
||||
|
||||
func bearerOpts(ctx context.Context) pool.CallOption {
|
||||
if tkn, err := tokens.LoadBearerToken(ctx); err == nil {
|
||||
return pool.WithBearer(tkn)
|
||||
|
|
23
downloader/download_test.go
Normal file
23
downloader/download_test.go
Normal file
|
@ -0,0 +1,23 @@
|
|||
package downloader
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestSystemBackwardTranslator(t *testing.T) {
|
||||
input := []string{
|
||||
"__NEOFS__EXPIRATION_EPOCH",
|
||||
"__NEOFS__RANDOM_ATTR",
|
||||
}
|
||||
expected := []string{
|
||||
"Neofs-Expiration-Epoch",
|
||||
"Neofs-Random-Attr",
|
||||
}
|
||||
|
||||
for i, str := range input {
|
||||
res := systemBackwardTranslator(str)
|
||||
require.Equal(t, expected[i], res)
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue