enabled htpasswd authentication

This commit is contained in:
Chapuis Bertil 2015-09-19 14:52:50 +02:00
parent 60fe10382a
commit 3a9283a115
2 changed files with 34 additions and 9 deletions

View file

@ -14,6 +14,21 @@ type Context struct {
path string
}
func AuthHandler(f *HtpasswdFile, h http.Handler) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
username, password, ok := r.BasicAuth()
if !ok {
http.Error(w, "401 unauthorized", 401)
return
}
if !f.Validate(username, password) {
http.Error(w, "401 unauthorized", 401)
return
}
h.ServeHTTP(w, r)
}
}
func CheckConfig(c *Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
config := filepath.Join(c.path, "config")