From a4cb2922fa61c482161accee421d0956de66f661 Mon Sep 17 00:00:00 2001 From: Tordarus Date: Fri, 14 Jan 2022 17:58:02 +0100 Subject: [PATCH] fix --- main.go | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/main.go b/main.go index a9a3958..8e5ff4d 100644 --- a/main.go +++ b/main.go @@ -27,14 +27,9 @@ var ( noauth = flag.Bool("a", false, "dont use basic auth") ) -var ( - fileServer http.Handler -) - func main() { flag.Parse() - fileServer = http.FileServer(http.Dir("")) http.HandleFunc("/", handler) dockerhealth.Healthy = true @@ -94,8 +89,14 @@ func get(w http.ResponseWriter, r *http.Request) { return } - r.URL.Path = path - fileServer.ServeHTTP(w, r) + file, err := os.Open(path) + if err != nil { + handleError(w, r, err) + return + } + defer file.Close() + + io.Copy(w, file) } func put(w http.ResponseWriter, r *http.Request) { @@ -143,9 +144,6 @@ func head(w http.ResponseWriter, r *http.Request) { w.Header().Add("File-Owner", username) w.Header().Add("Group-Owner", groupname) } - - r.URL.Path = path - fileServer.ServeHTTP(w, r) } func delete(w http.ResponseWriter, r *http.Request) {