From 0127bd130c42eb98a1f8a1ae0db04a9a13b4b525 Mon Sep 17 00:00:00 2001 From: Pierre Zemb Date: Sat, 18 Nov 2017 16:39:24 +0100 Subject: [PATCH] fix #9: right header to force authenticate More about basic auth: https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication --- auth.go | 2 ++ main.go | 1 + 2 files changed, 3 insertions(+) diff --git a/auth.go b/auth.go index 318e7ba..8a18a24 100644 --- a/auth.go +++ b/auth.go @@ -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" { diff --git a/main.go b/main.go index a1017cc..f3322bc 100644 --- a/main.go +++ b/main.go @@ -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 {