Skip to content

Commit

Permalink
add WWW-Authenticate header on auth failure
Browse files Browse the repository at this point in the history
  • Loading branch information
n8maninger committed Jan 24, 2024
1 parent 86116c8 commit 9355989
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions server.go
Expand Up @@ -215,6 +215,7 @@ func BasicAuth(password string) func(http.Handler) http.Handler {
return func(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
if _, p, ok := req.BasicAuth(); !ok || p != password {
w.Header().Set("WWW-Authenticate", `Basic realm="API Access", charset="UTF-8"`)
http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized)
return
}
Expand Down

0 comments on commit 9355989

Please sign in to comment.