Better error handling.

This commit is contained in:
Solderpunk 2019-04-22 09:18:00 -04:00
parent 46621b9617
commit 06aafc8261
1 changed files with 7 additions and 0 deletions

View File

@ -53,6 +53,10 @@ func GetHandler(config Config) http.HandlerFunc {
http.Error(w, "Not found.", http.StatusNotFound)
return
}
if os.IsPermission(err) {
http.Error(w, "Permission denied.", http.StatusForbidden)
return
}
// Fail if file is not world readable
if uint64(info.Mode().Perm())&0444 != 0444 {
http.Error(w, "File not world-readable.", http.StatusForbidden)
@ -62,6 +66,9 @@ func GetHandler(config Config) http.HandlerFunc {
// Get MIME type
ext := filepath.Ext(path)
mime := mime.TypeByExtension(ext)
if mime == "" {
http.Error(w, "MIME type detection error.", http.StatusInternalServerError)
}
// Fail if MIME type is forbidden
_, ok := config.BadMimesMap[mime]
if ok {