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 {
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)
return
}
@@ -1354,11 +1354,14 @@ func (s *Server) basicAuthHandler(h http.Handler) http.HandlerFunc {
}
username, password, authOK := r.BasicAuth()
if authOK {
if !authOK && !authorized {
http.Error(w, "Not authorized", http.StatusUnauthorized)
return
}
if !authorized && username == s.authUser && password == s.authPass {
authorized = true
}
}
if !authorized && s.htpasswdFile != nil {
authorized = s.htpasswdFile.Match(username, password)