From c78220a7f2aa804b4c718642e0ae0b6eaf6836e8 Mon Sep 17 00:00:00 2001 From: Konstantin Lebedev Date: Wed, 20 Oct 2021 16:01:06 +0500 Subject: [PATCH 1/4] fix object tagging https://github.com/chrislusf/seaweedfs/issues/2389 --- weed/s3api/s3api_object_tagging_handlers.go | 2 +- weed/s3api/s3err/s3api_errors.go | 2 +- weed/server/filer_server_handlers_read.go | 16 +++++++--------- .../filer_server_handlers_write_autochunk.go | 2 ++ 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/weed/s3api/s3api_object_tagging_handlers.go b/weed/s3api/s3api_object_tagging_handlers.go index 4daee5485..1ba1fb52d 100644 --- a/weed/s3api/s3api_object_tagging_handlers.go +++ b/weed/s3api/s3api_object_tagging_handlers.go @@ -90,7 +90,7 @@ func (s3a *S3ApiServer) PutObjectTaggingHandler(w http.ResponseWriter, r *http.R return } - w.WriteHeader(http.StatusNoContent) + w.WriteHeader(http.StatusOK) } diff --git a/weed/s3api/s3err/s3api_errors.go b/weed/s3api/s3err/s3api_errors.go index 30b7c03b3..3063df844 100644 --- a/weed/s3api/s3err/s3api_errors.go +++ b/weed/s3api/s3err/s3api_errors.go @@ -202,7 +202,7 @@ var errorCodeResponse = map[ErrorCode]APIError{ HTTPStatusCode: http.StatusBadRequest, }, ErrInvalidTag: { - Code: "InvalidArgument", + Code: "InvalidTag", Description: "The Tag value you have provided is invalid", HTTPStatusCode: http.StatusBadRequest, }, diff --git a/weed/server/filer_server_handlers_read.go b/weed/server/filer_server_handlers_read.go index c24e8780c..80b72bdef 100644 --- a/weed/server/filer_server_handlers_read.go +++ b/weed/server/filer_server_handlers_read.go @@ -113,17 +113,15 @@ func (fs *FilerServer) GetOrHeadHandler(w http.ResponseWriter, r *http.Request) w.Header().Set("Access-Control-Expose-Headers", strings.Join(seaweedHeaders, ",")) //set tag count - if r.Method == "GET" { - tagCount := 0 - for k := range entry.Extended { - if strings.HasPrefix(k, xhttp.AmzObjectTagging+"-") { - tagCount++ - } - } - if tagCount > 0 { - w.Header().Set(xhttp.AmzTagCount, strconv.Itoa(tagCount)) + tagCount := 0 + for k := range entry.Extended { + if strings.HasPrefix(k, xhttp.AmzObjectTagging+"-") { + tagCount++ } } + if tagCount > 0 { + w.Header().Set(xhttp.AmzTagCount, strconv.Itoa(tagCount)) + } if inm := r.Header.Get("If-None-Match"); inm == "\""+etag+"\"" { w.WriteHeader(http.StatusNotModified) diff --git a/weed/server/filer_server_handlers_write_autochunk.go b/weed/server/filer_server_handlers_write_autochunk.go index 1c230bad3..f2cb8142e 100644 --- a/weed/server/filer_server_handlers_write_autochunk.go +++ b/weed/server/filer_server_handlers_write_autochunk.go @@ -327,6 +327,8 @@ func SaveAmzMetaData(r *http.Request, existing map[string][]byte, isReplace bool tag := strings.Split(v, "=") if len(tag) == 2 { metadata[xhttp.AmzObjectTagging+"-"+tag[0]] = []byte(tag[1]) + } else if len(tag) == 1 { + metadata[xhttp.AmzObjectTagging+"-"+tag[0]] = nil } } } From 0b834600d5f8587990ce53c6c51b9508418bf44b Mon Sep 17 00:00:00 2001 From: Konstantin Lebedev Date: Wed, 20 Oct 2021 17:58:06 +0500 Subject: [PATCH 2/4] fix PutObjectTaggingHandler Unmarshal --- weed/s3api/tags.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/weed/s3api/tags.go b/weed/s3api/tags.go index 9ff7d1fba..5cb5f8e47 100644 --- a/weed/s3api/tags.go +++ b/weed/s3api/tags.go @@ -14,7 +14,7 @@ type TagSet struct { } type Tagging struct { - XMLName xml.Name `xml:"http://s3.amazonaws.com/doc/2006-03-01/ Tagging"` + XMLName xml.Name `xml:"Tagging"` TagSet TagSet `xml:"TagSet"` } From dc7e525cb983853c81a7e6f8f0e25e3f031a2b02 Mon Sep 17 00:00:00 2001 From: Konstantin Lebedev Date: Wed, 20 Oct 2021 19:12:00 +0500 Subject: [PATCH 3/4] fix Tagging test --- weed/s3api/tags.go | 1 + weed/s3api/tags_test.go | 1 + 2 files changed, 2 insertions(+) diff --git a/weed/s3api/tags.go b/weed/s3api/tags.go index 5cb5f8e47..9c1e91179 100644 --- a/weed/s3api/tags.go +++ b/weed/s3api/tags.go @@ -16,6 +16,7 @@ type TagSet struct { type Tagging struct { XMLName xml.Name `xml:"Tagging"` TagSet TagSet `xml:"TagSet"` + Xmlns string `xml:"xmlns,attr"` } func (t *Tagging) ToTags() map[string]string { diff --git a/weed/s3api/tags_test.go b/weed/s3api/tags_test.go index 52adb36c1..d8beb1922 100644 --- a/weed/s3api/tags_test.go +++ b/weed/s3api/tags_test.go @@ -32,6 +32,7 @@ func TestXMLUnmarshall(t *testing.T) { func TestXMLMarshall(t *testing.T) { tags := &Tagging{ + Xmlns: "http://s3.amazonaws.com/doc/2006-03-01/", TagSet: TagSet{ []Tag{ { From 235329a92a535650bc7f0556510ad6014eb15a70 Mon Sep 17 00:00:00 2001 From: Konstantin Lebedev Date: Wed, 20 Oct 2021 19:40:22 +0500 Subject: [PATCH 4/4] fix Tagging add xmlns --- weed/s3api/tags.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/weed/s3api/tags.go b/weed/s3api/tags.go index 9c1e91179..979e5a80c 100644 --- a/weed/s3api/tags.go +++ b/weed/s3api/tags.go @@ -28,7 +28,7 @@ func (t *Tagging) ToTags() map[string]string { } func FromTags(tags map[string]string) (t *Tagging) { - t = &Tagging{} + t = &Tagging{Xmlns: "http://s3.amazonaws.com/doc/2006-03-01/"} for k, v := range tags { t.TagSet.Tag = append(t.TagSet.Tag, Tag{ Key: k,