diff --git a/downloader/download.go b/downloader/download.go index d37ed32..7cd25e5 100644 --- a/downloader/download.go +++ b/downloader/download.go @@ -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) diff --git a/downloader/download_test.go b/downloader/download_test.go new file mode 100644 index 0000000..a47d12a --- /dev/null +++ b/downloader/download_test.go @@ -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) + } +}