mirror of
https://github.com/rclone/rclone.git
synced 2025-04-19 01:59:00 +08:00
Merge 35a37ab543bfdb1327e4c60f7fcffe7d79cd5b57 into 839eef0db269333870dc04cb79d0dd0c95e5a418
This commit is contained in:
commit
c1fa60adb0
@ -30,16 +30,18 @@ import (
|
||||
|
||||
// Options required for http server
|
||||
type Options struct {
|
||||
Auth libhttp.AuthConfig
|
||||
HTTP libhttp.Config
|
||||
Template libhttp.TemplateConfig
|
||||
Auth libhttp.AuthConfig
|
||||
HTTP libhttp.Config
|
||||
Template libhttp.TemplateConfig
|
||||
DisableDirList bool
|
||||
}
|
||||
|
||||
// DefaultOpt is the default values used for Options
|
||||
var DefaultOpt = Options{
|
||||
Auth: libhttp.DefaultAuthCfg(),
|
||||
HTTP: libhttp.DefaultCfg(),
|
||||
Template: libhttp.DefaultTemplateCfg(),
|
||||
Auth: libhttp.DefaultAuthCfg(),
|
||||
HTTP: libhttp.DefaultCfg(),
|
||||
Template: libhttp.DefaultTemplateCfg(),
|
||||
DisableDirList: false,
|
||||
}
|
||||
|
||||
// Opt is options set by command line flags
|
||||
@ -56,6 +58,7 @@ func init() {
|
||||
libhttp.AddTemplateFlagsPrefix(flagSet, flagPrefix, &Opt.Template)
|
||||
vfsflags.AddFlags(flagSet)
|
||||
proxyflags.AddFlags(flagSet)
|
||||
flagSet.BoolVarP(&Opt.DisableDirList, "disable-dir-list", "", false, "Disable HTML directory list on GET request for a directory")
|
||||
}
|
||||
|
||||
// Command definition for cobra
|
||||
@ -111,6 +114,16 @@ type HTTP struct {
|
||||
ctx context.Context // for global config
|
||||
}
|
||||
|
||||
// Empty template for use with --disable-dir-list
|
||||
const emptyDirListTemplate = `<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>`
|
||||
|
||||
|
||||
// Gets the VFS in use for this request
|
||||
func (s *HTTP) getVFS(ctx context.Context) (VFS *vfs.VFS, err error) {
|
||||
if s._vfs != nil {
|
||||
@ -212,6 +225,17 @@ func (s *HTTP) serveDir(w http.ResponseWriter, r *http.Request, dirRemote string
|
||||
serve.Error(ctx, dirRemote, w, "Failed to list directory", err)
|
||||
return
|
||||
}
|
||||
if Opt.DisableDirList {
|
||||
// Render the empty template
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
_, err := w.Write([]byte(emptyDirListTemplate))
|
||||
if err != nil {
|
||||
// Handle write error
|
||||
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
// Make the entries for display
|
||||
directory := serve.NewDirectory(dirRemote, s.server.HTMLTemplate())
|
||||
|
@ -672,6 +672,7 @@ rclone serve http remote:path [flags]
|
||||
--client-ca string Path to TLS PEM CA file with certificate authorities to verify clients with
|
||||
--dir-cache-time Duration Time to cache directory entries for (default 5m0s)
|
||||
--dir-perms FileMode Directory permissions (default 777)
|
||||
--disable-dir-list Disable HTML directory list on GET request for a directory
|
||||
--file-perms FileMode File permissions (default 666)
|
||||
--gid uint32 Override the gid field set by the filesystem (not supported on Windows) (default 1000)
|
||||
-h, --help help for http
|
||||
|
Loading…
x
Reference in New Issue
Block a user