fix verification; fix mime types

This commit is contained in:
Chris Sexton 2019-10-31 10:34:23 -04:00
parent a8560961ba
commit b04991dbd4
2 changed files with 19 additions and 4 deletions

View File

@ -8,7 +8,7 @@ import (
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
) )
var Develop = false var Develop = true
type RegisterResponse struct { type RegisterResponse struct {
ID string ID string

View File

@ -1,8 +1,10 @@
package web package web
import ( import (
"mime"
"net/http" "net/http"
"path" "path"
"path/filepath"
"github.com/rs/zerolog/log" "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") log.Error().Err(err).Msg("Error finding file")
w.WriteHeader(http.StatusNotFound) w.WriteHeader(http.StatusNotFound)
} }
w.Write(f) write(w, f, p)
return return
} }
if web.box.HasDir(p) && web.box.Has(path.Join(p, "index.html")) { 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") log.Error().Err(err).Msg("Error finding file")
w.WriteHeader(http.StatusNotFound) w.WriteHeader(http.StatusNotFound)
} }
w.Write(f) write(w, f, p)
return return
} }
if f, err := web.box.Find(p); err != nil { if f, err := web.box.Find(p); err != nil {
w.Write(f) write(w, f, p)
return return
} }
@ -39,3 +41,16 @@ func (web *Web) indexHandler(entryPoint string) func(w http.ResponseWriter, r *h
} }
return fn 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)
}