fix verification; fix mime types
This commit is contained in:
parent
a8560961ba
commit
b04991dbd4
|
@ -8,7 +8,7 @@ import (
|
|||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
var Develop = false
|
||||
var Develop = true
|
||||
|
||||
type RegisterResponse struct {
|
||||
ID string
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue