From d2a687bf2ae6f6af257cebdb80ee56a4cbbd7879 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Fri, 21 Sep 2012 21:18:11 +0200 Subject: "Manually" serve HTML files to set the correct header and to use the correct editor. --- src/ninjacloud.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/ninjacloud.go b/src/ninjacloud.go index 9f78cfb..3e1f3e3 100644 --- a/src/ninjacloud.go +++ b/src/ninjacloud.go @@ -115,10 +115,10 @@ func writeFile(path string, content []byte, overwrite bool) (err error) { return } -/*func readFile(path string) (content []byte, err error) { +func readFile(path string) (content []byte, err error) { content, err = ioutil.ReadFile(path) return -}*/ +} func removeFile(path string) (err error) { err = os.Remove(path) @@ -441,7 +441,21 @@ func fileHandler(w http.ResponseWriter, r *http.Request) { w.Write(j) return } else { - http.ServeFile(w, r, p) + ext := filepath.Ext(p) + if ext == ".htm" || ext == ".html" { + file, err := readFile(p) + if err != nil { + log.Println(err) + w.WriteHeader(http.StatusInternalServerError) + return + } + w.Header().Set("Content-Type", "text/plain, charset=utf-8") + w.WriteHeader(http.StatusOK) + w.Write(file) + return + } else { + http.ServeFile(w, r, p) + } } } } -- cgit v1.2.3