Browse Source

Merge pull request #2390 from kmlebedev/fix_tagging

pull/2395/head
Chris Lu 3 years ago
committed by GitHub
parent
commit
07dd4873db
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      weed/s3api/s3api_object_tagging_handlers.go
  2. 2
      weed/s3api/s3err/s3api_errors.go
  3. 5
      weed/s3api/tags.go
  4. 1
      weed/s3api/tags_test.go
  5. 2
      weed/server/filer_server_handlers_read.go
  6. 2
      weed/server/filer_server_handlers_write_autochunk.go

2
weed/s3api/s3api_object_tagging_handlers.go

@ -90,7 +90,7 @@ func (s3a *S3ApiServer) PutObjectTaggingHandler(w http.ResponseWriter, r *http.R
return return
} }
w.WriteHeader(http.StatusNoContent)
w.WriteHeader(http.StatusOK)
} }

2
weed/s3api/s3err/s3api_errors.go

@ -202,7 +202,7 @@ var errorCodeResponse = map[ErrorCode]APIError{
HTTPStatusCode: http.StatusBadRequest, HTTPStatusCode: http.StatusBadRequest,
}, },
ErrInvalidTag: { ErrInvalidTag: {
Code: "InvalidArgument",
Code: "InvalidTag",
Description: "The Tag value you have provided is invalid", Description: "The Tag value you have provided is invalid",
HTTPStatusCode: http.StatusBadRequest, HTTPStatusCode: http.StatusBadRequest,
}, },

5
weed/s3api/tags.go

@ -14,8 +14,9 @@ type TagSet struct {
} }
type Tagging 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"` TagSet TagSet `xml:"TagSet"`
Xmlns string `xml:"xmlns,attr"`
} }
func (t *Tagging) ToTags() map[string]string { func (t *Tagging) ToTags() map[string]string {
@ -27,7 +28,7 @@ func (t *Tagging) ToTags() map[string]string {
} }
func FromTags(tags map[string]string) (t *Tagging) { 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 { for k, v := range tags {
t.TagSet.Tag = append(t.TagSet.Tag, Tag{ t.TagSet.Tag = append(t.TagSet.Tag, Tag{
Key: k, Key: k,

1
weed/s3api/tags_test.go

@ -32,6 +32,7 @@ func TestXMLUnmarshall(t *testing.T) {
func TestXMLMarshall(t *testing.T) { func TestXMLMarshall(t *testing.T) {
tags := &Tagging{ tags := &Tagging{
Xmlns: "http://s3.amazonaws.com/doc/2006-03-01/",
TagSet: TagSet{ TagSet: TagSet{
[]Tag{ []Tag{
{ {

2
weed/server/filer_server_handlers_read.go

@ -113,7 +113,6 @@ func (fs *FilerServer) GetOrHeadHandler(w http.ResponseWriter, r *http.Request)
w.Header().Set("Access-Control-Expose-Headers", strings.Join(seaweedHeaders, ",")) w.Header().Set("Access-Control-Expose-Headers", strings.Join(seaweedHeaders, ","))
//set tag count //set tag count
if r.Method == "GET" {
tagCount := 0 tagCount := 0
for k := range entry.Extended { for k := range entry.Extended {
if strings.HasPrefix(k, xhttp.AmzObjectTagging+"-") { if strings.HasPrefix(k, xhttp.AmzObjectTagging+"-") {
@ -123,7 +122,6 @@ func (fs *FilerServer) GetOrHeadHandler(w http.ResponseWriter, r *http.Request)
if tagCount > 0 { if tagCount > 0 {
w.Header().Set(xhttp.AmzTagCount, strconv.Itoa(tagCount)) w.Header().Set(xhttp.AmzTagCount, strconv.Itoa(tagCount))
} }
}
if inm := r.Header.Get("If-None-Match"); inm == "\""+etag+"\"" { if inm := r.Header.Get("If-None-Match"); inm == "\""+etag+"\"" {
w.WriteHeader(http.StatusNotModified) w.WriteHeader(http.StatusNotModified)

2
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, "=") tag := strings.Split(v, "=")
if len(tag) == 2 { if len(tag) == 2 {
metadata[xhttp.AmzObjectTagging+"-"+tag[0]] = []byte(tag[1]) metadata[xhttp.AmzObjectTagging+"-"+tag[0]] = []byte(tag[1])
} else if len(tag) == 1 {
metadata[xhttp.AmzObjectTagging+"-"+tag[0]] = nil
} }
} }
} }

Loading…
Cancel
Save