add nocache flag
This commit is contained in:
13
main.go
13
main.go
@@ -16,6 +16,7 @@ type config struct {
|
||||
username string
|
||||
password string
|
||||
noindex bool
|
||||
nocache bool
|
||||
log bool
|
||||
}
|
||||
|
||||
@@ -28,6 +29,7 @@ func init() {
|
||||
flag.StringVar(&c.password, "password", "", "Require this password to access interface")
|
||||
flag.BoolVar(&c.noindex, "noindex", false, "Disable directory indexing")
|
||||
flag.BoolVar(&c.log, "log", false, "Enable simple request log")
|
||||
flag.BoolVar(&c.nocache, "nocache", false, "Set http headers to prevent caching of files")
|
||||
flag.Parse()
|
||||
}
|
||||
|
||||
@@ -42,7 +44,9 @@ func main() {
|
||||
if c.log {
|
||||
r.Use(queryLog)
|
||||
}
|
||||
|
||||
if c.nocache {
|
||||
r.Use(noCache)
|
||||
}
|
||||
if c.noindex {
|
||||
r.PathPrefix("/").Handler(http.StripPrefix("/", enhancedfileserver.FileServerNoIndex(http.Dir("./"))))
|
||||
} else {
|
||||
@@ -54,6 +58,13 @@ func main() {
|
||||
log.Fatal(http.ListenAndServe(a, r))
|
||||
}
|
||||
|
||||
func noCache(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Add("Cache-control", "no-cache, no-store")
|
||||
next.ServeHTTP(w,r)
|
||||
})
|
||||
}
|
||||
|
||||
func basicAuth(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if c.username != "" && c.password != "" {
|
||||
|
||||
Reference in New Issue
Block a user