From 392b9171e794446f596c75687f6fa5d76fb4cddd Mon Sep 17 00:00:00 2001 From: Julian Hurst Date: Thu, 23 Jan 2025 13:43:54 +0100 Subject: Use ServeFile instead of io.Copy --- main.go | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/main.go b/main.go index b5ff613..7326b43 100644 --- a/main.go +++ b/main.go @@ -49,14 +49,7 @@ func (handler BoxHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { serve(w, handler.token, "templates/index.html") } else { resourceId := path.Base(r.URL.Path) - f, err := os.Open(filepath.Join(handler.dataPath, resourceId)) - if err != nil { - log.Println(err) - w.WriteHeader(http.StatusBadRequest) - fmt.Fprint(w, err.Error()) - return - } - io.Copy(w, f) + http.ServeFile(w, r, filepath.Join(handler.dataPath, resourceId)) } return case http.MethodDelete: -- cgit v1.2.3