401 on hidden files/dirs
This commit is contained in:
parent
c3bcf30890
commit
4996fa50a2
6
main.go
6
main.go
@ -6,13 +6,19 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
var port = flag.Int("port", 8000, "port from which to serve")
|
var port = flag.Int("port", 8000, "port from which to serve")
|
||||||
|
var hidden = flag.Bool("hidden", false, "allow serving hidden dirs")
|
||||||
|
|
||||||
func logger(h http.Handler) http.Handler {
|
func logger(h http.Handler) http.Handler {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
log.Printf("%s: %s\n", r.RemoteAddr, r.URL)
|
log.Printf("%s: %s\n", r.RemoteAddr, r.URL)
|
||||||
|
if !*hidden && strings.Contains(r.URL.Path, "/.") {
|
||||||
|
http.Error(w, "hidden files and directories are not allowed", http.StatusUnauthorized)
|
||||||
|
return
|
||||||
|
}
|
||||||
h.ServeHTTP(w, r)
|
h.ServeHTTP(w, r)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user