From c9a0ba672e3864e3a78d06b8de44c388ca4b6bf0 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 21 Apr 2023 11:34:20 -0500 Subject: [PATCH] fix password but no username, update modules --- go.mod | 2 +- go.sum | 2 ++ main.go | 18 +++++++++++------- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index c439130..165510a 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,6 @@ module git.teamworkapps.com/shortcut/httphere go 1.17 require ( - git.teamworkapps.com/shortcut/enhancedfileserver v0.0.0-20181107163431-49cae39a0eb7 + git.teamworkapps.com/shortcut/enhancedfileserver v0.0.0-20230421162957-948ff8787756 github.com/gorilla/mux v1.8.0 ) diff --git a/go.sum b/go.sum index a9c17a7..094654b 100644 --- a/go.sum +++ b/go.sum @@ -1,4 +1,6 @@ git.teamworkapps.com/shortcut/enhancedfileserver v0.0.0-20181107163431-49cae39a0eb7 h1:wl0faTtewN9Y0nTZpRY2mcaIhVkaR1l8k920U0rDIk0= git.teamworkapps.com/shortcut/enhancedfileserver v0.0.0-20181107163431-49cae39a0eb7/go.mod h1:4t5y+BFcMRTe6GkAX72YXcjrKbGkOVM7CkJMRHNZYiQ= +git.teamworkapps.com/shortcut/enhancedfileserver v0.0.0-20230421162957-948ff8787756 h1:ViHTT1GI1JlsLrUsivl4tvg6DySn35d1C3bzXeLa8uY= +git.teamworkapps.com/shortcut/enhancedfileserver v0.0.0-20230421162957-948ff8787756/go.mod h1:Px7gD0CL+z9WBsvFPtCuDpVEJNStJXrbFRD3q7aJwYk= github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= diff --git a/main.go b/main.go index 8b1dddd..c92a398 100644 --- a/main.go +++ b/main.go @@ -16,7 +16,7 @@ type config struct { username string password string noindex bool - nocache bool + nocache bool log bool } @@ -35,18 +35,22 @@ func init() { func main() { r := mux.NewRouter() - if c.username != "" && c.password == "" { + if c.username == "" && c.password != "" { c.username = "admin" } - if c.username != "" && c.password != "" { - r.Use(basicAuth) - } + if c.log { r.Use(queryLog) } + + if c.username != "" && c.password != "" { + r.Use(basicAuth) + } + if c.nocache { r.Use(noCache) } + if c.noindex { r.PathPrefix("/").Handler(http.StripPrefix("/", enhancedfileserver.FileServerNoIndex(http.Dir("./")))) } else { @@ -60,8 +64,8 @@ func main() { 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) + w.Header().Add("Cache-control", "no-cache, no-store") + next.ServeHTTP(w, r) }) }