19 lines
453 B
Go
19 lines
453 B
Go
package server
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
)
|
|
|
|
// DisableDirectoryListings intercepts and responds with 404 to HTTP requests
|
|
// which would otherwise be served with a directory listing by http.FileServer.
|
|
func DisableDirectoryListings(next http.Handler) http.Handler {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
if strings.HasSuffix(r.URL.Path, "/") {
|
|
http.NotFound(w, r)
|
|
return
|
|
}
|
|
next.ServeHTTP(w, r)
|
|
})
|
|
}
|