Better error handling.
This commit is contained in:
parent
46621b9617
commit
06aafc8261
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue