Skip to content

Commit

Permalink
list objects: obey encoding-type
Browse files Browse the repository at this point in the history
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 to not URL encode keys which rclone
was doing before.

Fixes #4
  • Loading branch information
ncw committed Jan 11, 2025
1 parent 8287a58 commit 81e56a3
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions gofakes3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 81e56a3

Please sign in to comment.