diff --git a/web/user_handlers.go b/web/user_handlers.go index d15b394..41fc05d 100644 --- a/web/user_handlers.go +++ b/web/user_handlers.go @@ -8,7 +8,7 @@ import ( "github.com/rs/zerolog/log" ) -var Develop = false +var Develop = true type RegisterResponse struct { ID string diff --git a/web/web_handlers.go b/web/web_handlers.go index 80b7744..69d14ac 100644 --- a/web/web_handlers.go +++ b/web/web_handlers.go @@ -1,8 +1,10 @@ package web import ( + "mime" "net/http" "path" + "path/filepath" "github.com/rs/zerolog/log" ) @@ -17,7 +19,7 @@ func (web *Web) indexHandler(entryPoint string) func(w http.ResponseWriter, r *h log.Error().Err(err).Msg("Error finding file") w.WriteHeader(http.StatusNotFound) } - w.Write(f) + write(w, f, p) return } if web.box.HasDir(p) && web.box.Has(path.Join(p, "index.html")) { @@ -26,12 +28,12 @@ func (web *Web) indexHandler(entryPoint string) func(w http.ResponseWriter, r *h log.Error().Err(err).Msg("Error finding file") w.WriteHeader(http.StatusNotFound) } - w.Write(f) + write(w, f, p) return } if f, err := web.box.Find(p); err != nil { - w.Write(f) + write(w, f, p) return } @@ -39,3 +41,16 @@ func (web *Web) indexHandler(entryPoint string) func(w http.ResponseWriter, r *h } return fn } + +func write(w http.ResponseWriter, f []byte, path string) { + ctype := mime.TypeByExtension(filepath.Ext(path)) + log.Debug().Msgf("detected type %s for %s by extension", ctype, path) + if ctype == "" { + ctype = http.DetectContentType(f) + log.Debug().Msgf("detected type %s for %s by content", ctype, path) + } + if ctype != "" { + w.Header().Set("Content-Type", ctype) + } + w.Write(f) +}