Commit 30b19190 authored by Henrique Dias's avatar Henrique Dias

add ignoreIndexes option to browse

parent 840bc505
......@@ -26,6 +26,7 @@ type Browse struct {
Next middleware.Handler
Root string
Configs []Config
IgnoreIndexes bool
}
// Config is a configuration for browsing in a particular path.
......@@ -142,18 +143,20 @@ var IndexPages = []string{
"default.txt",
}
func directoryListing(files []os.FileInfo, r *http.Request, canGoUp bool, root string) (Listing, error) {
func directoryListing(files []os.FileInfo, r *http.Request, canGoUp bool, root string, ignoreIndexes bool) (Listing, error) {
var fileinfos []FileInfo
var urlPath = r.URL.Path
for _, f := range files {
name := f.Name()
// Directory is not browsable if it contains index file
if !ignoreIndexes {
for _, indexName := range IndexPages {
if name == indexName {
return Listing{}, errors.New("Directory contains index file, not browsable!")
}
}
}
if f.IsDir() {
name += "/"
......@@ -234,7 +237,7 @@ func (b Browse) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) {
}
}
// Assemble listing of directory contents
listing, err := directoryListing(files, r, canGoUp, b.Root)
listing, err := directoryListing(files, r, canGoUp, b.Root, b.IgnoreIndexes)
if err != nil { // directory isn't browsable
continue
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment