mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
Adding filer option disableDirListing
This commit is contained in:
parent
95c373e762
commit
98aa9cc068
|
@ -22,6 +22,7 @@ type FilerOptions struct {
|
||||||
defaultReplicaPlacement *string
|
defaultReplicaPlacement *string
|
||||||
dir *string
|
dir *string
|
||||||
redirectOnRead *bool
|
redirectOnRead *bool
|
||||||
|
disableDirListing *bool
|
||||||
secretKey *string
|
secretKey *string
|
||||||
cassandra_server *string
|
cassandra_server *string
|
||||||
cassandra_keyspace *string
|
cassandra_keyspace *string
|
||||||
|
@ -37,6 +38,7 @@ func init() {
|
||||||
f.dir = cmdFiler.Flag.String("dir", os.TempDir(), "directory to store meta data")
|
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.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.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_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.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")
|
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()
|
r := http.NewServeMux()
|
||||||
_, nfs_err := weed_server.NewFilerServer(r, *f.port, *f.master, *f.dir, *f.collection,
|
_, 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.secretKey,
|
||||||
*f.cassandra_server, *f.cassandra_keyspace,
|
*f.cassandra_server, *f.cassandra_keyspace,
|
||||||
*f.redis_server, *f.redis_database,
|
*f.redis_server, *f.redis_database,
|
||||||
|
|
|
@ -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.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.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.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_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.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")
|
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() {
|
go func() {
|
||||||
r := http.NewServeMux()
|
r := http.NewServeMux()
|
||||||
_, nfs_err := weed_server.NewFilerServer(r, *filerOptions.port, *filerOptions.master, *filerOptions.dir, *filerOptions.collection,
|
_, 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,
|
*filerOptions.secretKey,
|
||||||
"", "",
|
"", "",
|
||||||
"", 0,
|
"", 0,
|
||||||
|
|
|
@ -19,12 +19,13 @@ type FilerServer struct {
|
||||||
collection string
|
collection string
|
||||||
defaultReplication string
|
defaultReplication string
|
||||||
redirectOnRead bool
|
redirectOnRead bool
|
||||||
|
disableDirListing bool
|
||||||
secret security.Secret
|
secret security.Secret
|
||||||
filer filer.Filer
|
filer filer.Filer
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFilerServer(r *http.ServeMux, port int, master string, dir string, collection string,
|
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,
|
secret string,
|
||||||
cassandra_server string, cassandra_keyspace string,
|
cassandra_server string, cassandra_keyspace string,
|
||||||
redis_server string, redis_database int,
|
redis_server string, redis_database int,
|
||||||
|
@ -34,6 +35,7 @@ func NewFilerServer(r *http.ServeMux, port int, master string, dir string, colle
|
||||||
collection: collection,
|
collection: collection,
|
||||||
defaultReplication: replication,
|
defaultReplication: replication,
|
||||||
redirectOnRead: redirectOnRead,
|
redirectOnRead: redirectOnRead,
|
||||||
|
disableDirListing: disableDirListing,
|
||||||
port: ":" + strconv.Itoa(port),
|
port: ":" + strconv.Itoa(port),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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) {
|
func (fs *FilerServer) GetOrHeadHandler(w http.ResponseWriter, r *http.Request, isGetMethod bool) {
|
||||||
if strings.HasSuffix(r.URL.Path, "/") {
|
if strings.HasSuffix(r.URL.Path, "/") {
|
||||||
|
if fs.disableDirListing {
|
||||||
|
w.WriteHeader(http.StatusMethodNotAllowed)
|
||||||
|
return
|
||||||
|
}
|
||||||
fs.listDirectoryHandler(w, r)
|
fs.listDirectoryHandler(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue