forked from TrueCloudLab/frostfs-http-gw
Nikita Zinkevich
72530c57ca
During upload if "X-Explode-Archive" is set, gate tries to read archive and creates an object for each file. Each object acquires a FilePath attribute which is calculated relative to the archive root Signed-off-by: Nikita Zinkevich <n.zinkevich@yadro.com>
57 lines
1.3 KiB
Go
57 lines
1.3 KiB
Go
package handler
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-http-gw/internal/logs"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-http-gw/utils"
|
|
"github.com/valyala/fasthttp"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
func filterHeaders(l *zap.Logger, header *fasthttp.RequestHeader) (map[string]string, error) {
|
|
var err error
|
|
result := make(map[string]string)
|
|
prefix := []byte(utils.UserAttributeHeaderPrefix)
|
|
|
|
header.VisitAll(func(key, val []byte) {
|
|
// checks that the key and the val not empty
|
|
if len(key) == 0 || len(val) == 0 {
|
|
return
|
|
}
|
|
|
|
// checks that the key has attribute prefix
|
|
if !bytes.HasPrefix(key, prefix) {
|
|
return
|
|
}
|
|
|
|
// removing attribute prefix
|
|
clearKey := bytes.TrimPrefix(key, prefix)
|
|
|
|
clearKey = utils.TransformIfSystem(clearKey)
|
|
|
|
// checks that the attribute key is not empty
|
|
if len(clearKey) == 0 {
|
|
return
|
|
}
|
|
|
|
// check if key gets duplicated
|
|
// return error containing full key name (with prefix)
|
|
if _, ok := result[string(clearKey)]; ok {
|
|
err = fmt.Errorf("header key duplication error: %s", string(key))
|
|
return
|
|
}
|
|
|
|
// make string representation of key / val
|
|
k, v := string(clearKey), string(val)
|
|
|
|
result[k] = v
|
|
|
|
l.Debug(logs.AddAttributeToResultObject,
|
|
zap.String("key", k),
|
|
zap.String("val", v))
|
|
})
|
|
|
|
return result, err
|
|
}
|