fix #9: right header to force authenticate

More about basic auth: https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication
This commit is contained in:
Pierre Zemb 2017-11-18 16:39:24 +01:00
parent 8a712d9155
commit 0127bd130c
No known key found for this signature in database
GPG key ID: E48ABD1BBB7FEC23
2 changed files with 3 additions and 0 deletions

View file

@ -13,6 +13,8 @@ import (
func authMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("WWW-Authenticate", `Basic realm="Restricted"`)
auth := strings.SplitN(r.Header.Get("Authorization"), " ", 2)
if len(auth) != 2 || auth[0] != "Basic" {

View file

@ -50,6 +50,7 @@ func main() {
handler := http.FileServer(http.Dir(*path))
if *basicAuth {
log.Println("Enabling Basic Auth")
if len(*setBasicAuth) != 0 {
parseAuth(*setBasicAuth)
} else {