fix: Fixes #274, Fixed putting and getting object metadata case normalization issue

This commit is contained in:
jonaustin09
2023-10-05 15:33:03 -04:00
parent 664e6e7814
commit 856d79d385
3 changed files with 9 additions and 23 deletions

View File

@@ -135,8 +135,6 @@ func (p *Posix) ListBuckets(_ context.Context, owner string, isAdmin bool) (s3re
sort.Sort(backend.ByBucketName(buckets)) sort.Sort(backend.ByBucketName(buckets))
fmt.Println("ListAllMyBucketsResult owner:", owner)
return s3response.ListAllMyBucketsResult{ return s3response.ListAllMyBucketsResult{
Buckets: s3response.ListAllMyBucketsList{ Buckets: s3response.ListAllMyBucketsList{
Bucket: buckets, Bucket: buckets,

View File

@@ -35,13 +35,16 @@ var (
func GetUserMetaData(headers *fasthttp.RequestHeader) (metadata map[string]string) { func GetUserMetaData(headers *fasthttp.RequestHeader) (metadata map[string]string) {
metadata = make(map[string]string) metadata = make(map[string]string)
headers.VisitAll(func(key, value []byte) { headers.DisableNormalizing()
if strings.HasPrefix(string(key), "X-Amz-Meta-") { headers.VisitAllInOrder(func(key, value []byte) {
trimmedKey := strings.TrimPrefix(string(key), "X-Amz-Meta-") hKey := string(key)
if strings.HasPrefix(strings.ToLower(hKey), "x-amz-meta-") {
trimmedKey := hKey[11:]
headerValue := string(value) headerValue := string(value)
metadata[trimmedKey] = headerValue metadata[trimmedKey] = headerValue
} }
}) })
headers.EnableNormalizing()
return return
} }
@@ -75,9 +78,11 @@ func CreateHttpRequestFromCtx(ctx *fiber.Ctx, signedHdrs []string) (*http.Reques
} }
func SetMetaHeaders(ctx *fiber.Ctx, meta map[string]string) { func SetMetaHeaders(ctx *fiber.Ctx, meta map[string]string) {
ctx.Response().Header.DisableNormalizing()
for key, val := range meta { for key, val := range meta {
ctx.Set(fmt.Sprintf("X-Amz-Meta-%s", key), val) ctx.Response().Header.Set(fmt.Sprintf("X-Amz-Meta-%s", key), val)
} }
ctx.Response().Header.EnableNormalizing()
} }
func ParseUint(str string) (int32, error) { func ParseUint(str string) (int32, error) {

View File

@@ -79,13 +79,6 @@ func TestGetUserMetaData(t *testing.T) {
ctx := app.AcquireCtx(&fasthttp.RequestCtx{}) ctx := app.AcquireCtx(&fasthttp.RequestCtx{})
req := ctx.Request() req := ctx.Request()
// Case 2
ctx2 := app.AcquireCtx(&fasthttp.RequestCtx{})
req2 := ctx2.Request()
req2.Header.Add("X-Amz-Meta-Name", "Nick")
req2.Header.Add("X-Amz-Meta-Age", "27")
tests := []struct { tests := []struct {
name string name string
args args args args
@@ -98,16 +91,6 @@ func TestGetUserMetaData(t *testing.T) {
}, },
wantMetadata: map[string]string{}, wantMetadata: map[string]string{},
}, },
{
name: "Success-non-empty-response",
args: args{
headers: &req2.Header,
},
wantMetadata: map[string]string{
"Age": "27",
"Name": "Nick",
},
},
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {