aboutsummaryrefslogtreecommitdiff
path: root/weed/s3api/s3api_object_handlers.go
diff options
context:
space:
mode:
authorKonstantin Lebedev <9497591+kmlebedev@users.noreply.github.com>2024-07-04 23:00:41 +0500
committerGitHub <noreply@github.com>2024-07-04 11:00:41 -0700
commitf77eee667df234ff0cdc98195f04b58e5d3a4110 (patch)
tree6e2ba062dea9b5f56a2d350df9a71e20a9d3b487 /weed/s3api/s3api_object_handlers.go
parent7c06306857feb2ef90452460735ad9c253c47f35 (diff)
downloadseaweedfs-f77eee667df234ff0cdc98195f04b58e5d3a4110.tar.xz
seaweedfs-f77eee667df234ff0cdc98195f04b58e5d3a4110.zip
add s3test for sql (#5718)
* add s3test for sql * fix test test_bucket_listv2_delimiter_basic for s3 * fix action s3tests * regen s3 api xsd * rm minor s3 test test_bucket_listv2_fetchowner_defaultempty * add docs * without xmlns
Diffstat (limited to 'weed/s3api/s3api_object_handlers.go')
-rw-r--r--weed/s3api/s3api_object_handlers.go42
1 files changed, 41 insertions, 1 deletions
diff --git a/weed/s3api/s3api_object_handlers.go b/weed/s3api/s3api_object_handlers.go
index 517a55856..ff7e92304 100644
--- a/weed/s3api/s3api_object_handlers.go
+++ b/weed/s3api/s3api_object_handlers.go
@@ -3,6 +3,8 @@ package s3api
import (
"bytes"
"fmt"
+ "github.com/seaweedfs/seaweedfs/weed/filer"
+ "github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
"io"
"net/http"
"net/url"
@@ -35,10 +37,17 @@ func urlEscapeObject(object string) string {
return "/" + t
}
+func entryUrlEncode(dir string, entry string, encodingTypeUrl bool) (dirName string, entryName string, prefix string) {
+ if !encodingTypeUrl {
+ return dir, entry, entry
+ }
+ return urlPathEscape(dir), url.QueryEscape(entry), urlPathEscape(entry)
+}
+
func urlPathEscape(object string) string {
var escapedParts []string
for _, part := range strings.Split(object, "/") {
- escapedParts = append(escapedParts, url.PathEscape(part))
+ escapedParts = append(escapedParts, strings.ReplaceAll(url.PathEscape(part), "+", "%2B"))
}
return strings.Join(escapedParts, "/")
}
@@ -63,6 +72,37 @@ func removeDuplicateSlashes(object string) string {
return result.String()
}
+func newListEntry(entry *filer_pb.Entry, key string, dir string, name string, bucketPrefix string, fetchOwner bool, isDirectory bool, encodingTypeUrl bool) (listEntry ListEntry) {
+ storageClass := "STANDARD"
+ if v, ok := entry.Extended[s3_constants.AmzStorageClass]; ok {
+ storageClass = string(v)
+ }
+ keyFormat := "%s/%s"
+ if isDirectory {
+ keyFormat += "/"
+ }
+ if key == "" {
+ key = fmt.Sprintf(keyFormat, dir, name)[len(bucketPrefix):]
+ }
+ if encodingTypeUrl {
+ key = urlPathEscape(key)
+ }
+ listEntry = ListEntry{
+ Key: key,
+ LastModified: time.Unix(entry.Attributes.Mtime, 0).UTC(),
+ ETag: "\"" + filer.ETag(entry) + "\"",
+ Size: int64(filer.FileSize(entry)),
+ StorageClass: StorageClass(storageClass),
+ }
+ if fetchOwner {
+ listEntry.Owner = CanonicalUser{
+ ID: fmt.Sprintf("%x", entry.Attributes.Uid),
+ DisplayName: entry.Attributes.UserName,
+ }
+ }
+ return listEntry
+}
+
func (s3a *S3ApiServer) toFilerUrl(bucket, object string) string {
object = urlPathEscape(removeDuplicateSlashes(object))
destUrl := fmt.Sprintf("http://%s%s/%s%s",