From a44784d84a02398b9e3927beed9fb1b10f314587 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Sat, 28 Dec 2024 12:06:40 +0000 Subject: [PATCH] list objects: obey encoding-type Before this change we unconditionally set encoding-type=url which was confusing some clients. After this change we do url encoding only if it was requested. NB This will require the backend not to URL encoding keys which rclone was doing before. Fixes #4 --- gofakes3.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/gofakes3.go b/gofakes3.go index b8c25f3..4d01e53 100644 --- a/gofakes3.go +++ b/gofakes3.go @@ -235,6 +235,11 @@ func (g *GoFakeS3) listBucket(bucketName string, w http.ResponseWriter, r *http. } isVersion2 := q.Get("list-type") == "2" + encodingType := q.Get("encoding-type") + useUrlEncoding := encodingType == "url" + if !useUrlEncoding && encodingType != "" { + return ErrInvalidArgument + } g.log.Print(LogInfo, "bucketname:", bucketName, "prefix:", prefix, "page:", fmt.Sprintf("%+v", page)) @@ -266,9 +271,19 @@ func (g *GoFakeS3) listBucket(bucketName string, w http.ResponseWriter, r *http. Contents: objects.Contents, IsTruncated: objects.IsTruncated, Delimiter: prefix.Delimiter, - Prefix: URLEncode(prefix.Prefix), + Prefix: prefix.Prefix, MaxKeys: page.MaxKeys, - EncodingType: "url", + EncodingType: encodingType, + } + if useUrlEncoding { + base.Prefix = URLEncode(base.Prefix) + for i := range base.CommonPrefixes { + prefix := &base.CommonPrefixes[i] + prefix.Prefix = URLEncode(prefix.Prefix) + } + for _, content := range base.Contents { + content.Key = URLEncode(content.Key) + } } if !isVersion2 {