fix #9: right header to force authenticate
More about basic auth: https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication
This commit is contained in:
parent
8a712d9155
commit
0127bd130c
2 changed files with 3 additions and 0 deletions
2
auth.go
2
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" {
|
||||
|
|
1
main.go
1
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 {
|
||||
|
|
Loading…
Reference in a new issue