diff --git a/go/weed/filer.go b/go/weed/filer.go index fd7dcdf88..f09edebb1 100644 --- a/go/weed/filer.go +++ b/go/weed/filer.go @@ -22,6 +22,7 @@ type FilerOptions struct { defaultReplicaPlacement *string dir *string redirectOnRead *bool + disableDirListing *bool secretKey *string cassandra_server *string cassandra_keyspace *string @@ -37,6 +38,7 @@ func init() { f.dir = cmdFiler.Flag.String("dir", os.TempDir(), "directory to store meta data") f.defaultReplicaPlacement = cmdFiler.Flag.String("defaultReplicaPlacement", "000", "default replication type if not specified") f.redirectOnRead = cmdFiler.Flag.Bool("redirectOnRead", false, "whether proxy or redirect to volume server during file GET request") + f.disableDirListing = cmdFiler.Flag.Bool("disableDirListing", false, "turn off directory listing") f.cassandra_server = cmdFiler.Flag.String("cassandra.server", "", "host[:port] of the cassandra server") f.cassandra_keyspace = cmdFiler.Flag.String("cassandra.keyspace", "seaweed", "keyspace of the cassandra server") f.redis_server = cmdFiler.Flag.String("redis.server", "", "host:port of the redis server, e.g., 127.0.0.1:6379") @@ -75,7 +77,7 @@ func runFiler(cmd *Command, args []string) bool { r := http.NewServeMux() _, nfs_err := weed_server.NewFilerServer(r, *f.port, *f.master, *f.dir, *f.collection, - *f.defaultReplicaPlacement, *f.redirectOnRead, + *f.defaultReplicaPlacement, *f.redirectOnRead, *f.disableDirListing, *f.secretKey, *f.cassandra_server, *f.cassandra_keyspace, *f.redis_server, *f.redis_database, diff --git a/go/weed/server.go b/go/weed/server.go index 910201966..2c31c122c 100644 --- a/go/weed/server.go +++ b/go/weed/server.go @@ -84,6 +84,7 @@ func init() { filerOptions.dir = cmdServer.Flag.String("filer.dir", "", "directory to store meta data, default to a 'filer' sub directory of what -mdir is specified") filerOptions.defaultReplicaPlacement = cmdServer.Flag.String("filer.defaultReplicaPlacement", "", "Default replication type if not specified during runtime.") filerOptions.redirectOnRead = cmdServer.Flag.Bool("filer.redirectOnRead", false, "whether proxy or redirect to volume server during file GET request") + filerOptions.disableDirListing = cmdServer.Flag.Bool("filer.disableDirListing", false, "turn off directory listing") filerOptions.cassandra_server = cmdServer.Flag.String("filer.cassandra.server", "", "host[:port] of the cassandra server") filerOptions.cassandra_keyspace = cmdServer.Flag.String("filer.cassandra.keyspace", "seaweed", "keyspace of the cassandra server") filerOptions.redis_server = cmdServer.Flag.String("filer.redis.server", "", "host:port of the redis server, e.g., 127.0.0.1:6379") @@ -163,7 +164,8 @@ func runServer(cmd *Command, args []string) bool { go func() { r := http.NewServeMux() _, nfs_err := weed_server.NewFilerServer(r, *filerOptions.port, *filerOptions.master, *filerOptions.dir, *filerOptions.collection, - *filerOptions.defaultReplicaPlacement, *filerOptions.redirectOnRead, + *filerOptions.defaultReplicaPlacement, + *filerOptions.redirectOnRead, *filerOptions.disableDirListing, *filerOptions.secretKey, "", "", "", 0, diff --git a/go/weed/weed_server/filer_server.go b/go/weed/weed_server/filer_server.go index 1309e4486..8bb094208 100644 --- a/go/weed/weed_server/filer_server.go +++ b/go/weed/weed_server/filer_server.go @@ -19,12 +19,13 @@ type FilerServer struct { collection string defaultReplication string redirectOnRead bool + disableDirListing bool secret security.Secret filer filer.Filer } func NewFilerServer(r *http.ServeMux, port int, master string, dir string, collection string, - replication string, redirectOnRead bool, + replication string, redirectOnRead bool, disableDirListing bool, secret string, cassandra_server string, cassandra_keyspace string, redis_server string, redis_database int, @@ -34,6 +35,7 @@ func NewFilerServer(r *http.ServeMux, port int, master string, dir string, colle collection: collection, defaultReplication: replication, redirectOnRead: redirectOnRead, + disableDirListing: disableDirListing, port: ":" + strconv.Itoa(port), } diff --git a/go/weed/weed_server/filer_server_handlers.go b/go/weed/weed_server/filer_server_handlers.go index 6278e5dad..11a07b0ae 100644 --- a/go/weed/weed_server/filer_server_handlers.go +++ b/go/weed/weed_server/filer_server_handlers.go @@ -54,6 +54,10 @@ func (fs *FilerServer) listDirectoryHandler(w http.ResponseWriter, r *http.Reque } func (fs *FilerServer) GetOrHeadHandler(w http.ResponseWriter, r *http.Request, isGetMethod bool) { if strings.HasSuffix(r.URL.Path, "/") { + if fs.disableDirListing { + w.WriteHeader(http.StatusMethodNotAllowed) + return + } fs.listDirectoryHandler(w, r) return }