Browse Source

Avoid xattr printed out as HTTP headers

fix https://github.com/chrislusf/seaweedfs/issues/2336
pull/2348/head
Chris Lu 3 years ago
parent
commit
7504be58f9
  1. 19
      weed/filesys/xattr.go
  2. 5
      weed/server/filer_server_handlers_read.go

19
weed/filesys/xattr.go

@ -2,6 +2,7 @@ package filesys
import (
"context"
"strings"
"github.com/seaweedfs/fuse"
@ -10,6 +11,10 @@ import (
"github.com/chrislusf/seaweedfs/weed/util"
)
const (
XATTR_PREFIX = "xattr-" // same as filer
)
func getxattr(entry *filer_pb.Entry, req *fuse.GetxattrRequest, resp *fuse.GetxattrResponse) error {
if entry == nil {
@ -18,7 +23,7 @@ func getxattr(entry *filer_pb.Entry, req *fuse.GetxattrRequest, resp *fuse.Getxa
if entry.Extended == nil {
return fuse.ErrNoXattr
}
data, found := entry.Extended[req.Name]
data, found := entry.Extended[XATTR_PREFIX+req.Name]
if !found {
return fuse.ErrNoXattr
}
@ -47,7 +52,7 @@ func setxattr(entry *filer_pb.Entry, req *fuse.SetxattrRequest) error {
if entry.Extended == nil {
entry.Extended = make(map[string][]byte)
}
data, _ := entry.Extended[req.Name]
data, _ := entry.Extended[XATTR_PREFIX+req.Name]
newData := make([]byte, int(req.Position)+len(req.Xattr))
@ -55,7 +60,7 @@ func setxattr(entry *filer_pb.Entry, req *fuse.SetxattrRequest) error {
copy(newData[int(req.Position):], req.Xattr)
entry.Extended[req.Name] = newData
entry.Extended[XATTR_PREFIX+req.Name] = newData
return nil
@ -71,13 +76,13 @@ func removexattr(entry *filer_pb.Entry, req *fuse.RemovexattrRequest) error {
return fuse.ErrNoXattr
}
_, found := entry.Extended[req.Name]
_, found := entry.Extended[XATTR_PREFIX+req.Name]
if !found {
return fuse.ErrNoXattr
}
delete(entry.Extended, req.Name)
delete(entry.Extended, XATTR_PREFIX+req.Name)
return nil
@ -90,7 +95,9 @@ func listxattr(entry *filer_pb.Entry, req *fuse.ListxattrRequest, resp *fuse.Lis
}
for k := range entry.Extended {
resp.Append(k)
if strings.HasPrefix(k, XATTR_PREFIX) {
resp.Append(k[len(XATTR_PREFIX):])
}
}
size := req.Size

5
weed/server/filer_server_handlers_read.go

@ -97,7 +97,10 @@ func (fs *FilerServer) GetOrHeadHandler(w http.ResponseWriter, r *http.Request)
// print out the header from extended properties
for k, v := range entry.Extended {
w.Header().Set(k, string(v))
if !strings.HasPrefix(k, "xattr-") {
// "xattr-" prefix is set in filesys.XATTR_PREFIX
w.Header().Set(k, string(v))
}
}
//Seaweed custom header are not visible to Vue or javascript

Loading…
Cancel
Save