From 2323cf3f89be0b60074a8735fd6da3faea467478 Mon Sep 17 00:00:00 2001 From: Reinaldy Rafli Date: Fri, 5 May 2023 22:29:56 +0700 Subject: [PATCH] fix: provide content type for any other result --- main.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/main.go b/main.go index 19e9535..c7999dc 100644 --- a/main.go +++ b/main.go @@ -17,6 +17,7 @@ import ( var baseDirectory string func handler(w http.ResponseWriter, r *http.Request) { + log.Printf("Incoming request: %s %s", r.Method, r.URL.Path) filePath := path.Join(baseDirectory, r.URL.Path) file, err := os.Stat(filePath) if err == nil && !file.IsDir() { @@ -29,6 +30,7 @@ func handler(w http.ResponseWriter, r *http.Request) { w.Header().Add("Content-Type", t) http.ServeFile(w, r, gz) } else { + w.Header().Add("Content-Type", t) http.ServeFile(w, r, filePath) } } else { @@ -37,6 +39,7 @@ func handler(w http.ResponseWriter, r *http.Request) { file, err := os.Stat(index) if err == nil && !file.IsDir() { // index.html exists + w.Header().Add("Content-Type", "text/html") http.ServeFile(w, r, index) } else { // index.html does not exist