Append index.html to directories when resolving paths.

This commit is contained in:
Solderpunk 2019-04-22 09:18:25 -04:00
parent 06aafc8261
commit 309dd05f4d
1 changed files with 9 additions and 0 deletions

View File

@ -57,6 +57,15 @@ func GetHandler(config Config) http.HandlerFunc {
http.Error(w, "Permission denied.", http.StatusForbidden)
return
}
// Add index.html to directory paths, if it exists
if info.IsDir() {
index_path := filepath.Join(path, "index.html")
index_info, err := os.Stat(index_path)
if !os.IsNotExist(err) {
path = index_path
info = index_info
}
}
// Fail if file is not world readable
if uint64(info.Mode().Perm())&0444 != 0444 {
http.Error(w, "File not world-readable.", http.StatusForbidden)