From 56106f21f72ad9add8c208aa519b55e106d988bd Mon Sep 17 00:00:00 2001 From: shengxiang Date: Thu, 28 Dec 2017 16:09:54 +0800 Subject: [PATCH 1/2] fix appendReloadHook not working bug --- http-watcher.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/http-watcher.go b/http-watcher.go index b44ee5a..b14af12 100644 --- a/http-watcher.go +++ b/http-watcher.go @@ -234,8 +234,11 @@ func fileHandler(w http.ResponseWriter, path string, req *http.Request) { } w.Header().Set("Content-Type", ctype) } - if fi, err := os.Stat(path); err == nil { - w.Header().Set("Content-Length", fmt.Sprintf("%d", fi.Size())) + // text/html has larger size after appendReloadHook + if !strings.HasPrefix(ctype, "text/html") { + if fi, err := os.Stat(path); err == nil { + w.Header().Set("Content-Length", fmt.Sprintf("%d", fi.Size())) + } } w.WriteHeader(200) io.Copy(w, f) From d6389541a6196db0f33bbce31f61db3f56d456f0 Mon Sep 17 00:00:00 2001 From: codeskyblue Date: Fri, 23 Nov 2018 16:04:25 +0800 Subject: [PATCH 2/2] fix html video not support Range --- http-watcher.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/http-watcher.go b/http-watcher.go index b14af12..0f44bcb 100644 --- a/http-watcher.go +++ b/http-watcher.go @@ -235,14 +235,13 @@ func fileHandler(w http.ResponseWriter, path string, req *http.Request) { w.Header().Set("Content-Type", ctype) } // text/html has larger size after appendReloadHook - if !strings.HasPrefix(ctype, "text/html") { - if fi, err := os.Stat(path); err == nil { - w.Header().Set("Content-Length", fmt.Sprintf("%d", fi.Size())) - } + if strings.HasPrefix(ctype, "text/html") { + w.WriteHeader(200) + io.Copy(w, f) + appendReloadHook(w, ctype, req) + return } - w.WriteHeader(200) - io.Copy(w, f) - appendReloadHook(w, ctype, req) + http.ServeFile(w, req, path) } }