better logic

This commit is contained in:
Andrea Spacca
2023-06-06 19:35:45 +09:00
parent fc6f897eaa
commit c5664b433d

View File

@@ -1326,7 +1326,7 @@ func ipFilterHandler(h http.Handler, ipFilterOptions *IPFilterOptions) http.Hand
func (s *Server) basicAuthHandler(h http.Handler) http.HandlerFunc { func (s *Server) basicAuthHandler(h http.Handler) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
if (s.authUser == "" || s.authPass == "") && s.authHtpasswd == "" { if s.authUser == "" && s.authPass == "" && s.authHtpasswd == "" {
h.ServeHTTP(w, r) h.ServeHTTP(w, r)
return return
} }
@@ -1354,10 +1354,13 @@ func (s *Server) basicAuthHandler(h http.Handler) http.HandlerFunc {
} }
username, password, authOK := r.BasicAuth() username, password, authOK := r.BasicAuth()
if authOK { if !authOK && !authorized {
if !authorized && username == s.authUser && password == s.authPass { http.Error(w, "Not authorized", http.StatusUnauthorized)
authorized = true return
} }
if !authorized && username == s.authUser && password == s.authPass {
authorized = true
} }
if !authorized && s.htpasswdFile != nil { if !authorized && s.htpasswdFile != nil {