Skip to content

Commit

Permalink
Basic auth: Fix #201 - broken uploads
Browse files Browse the repository at this point in the history
  • Loading branch information
andreimarcu committed Mar 11, 2020
1 parent 7ca3331 commit 773eb87
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
2 changes: 1 addition & 1 deletion auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func badAuthorizationHandler(w http.ResponseWriter, r *http.Request) {
if Config.siteName != "" {
rs = fmt.Sprintf(` realm="%s"`, Config.siteName)
}
w.Header().Set("WWW-Authenticate", `Basic` + rs)
w.Header().Set("WWW-Authenticate", `Basic`+rs)
}
http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized)
}
Expand Down
6 changes: 2 additions & 4 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,20 +196,18 @@ func setup() *web.Mux {
AuthFile: Config.authFile,
UnauthMethods: []string{},
}
okFunc := func (w http.ResponseWriter, r *http.Request) {
okFunc := func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Location", Config.sitePath)
w.WriteHeader(http.StatusFound)
}
authHandler := auth {
authHandler := auth{
successHandler: http.HandlerFunc(okFunc),
failureHandler: http.HandlerFunc(badAuthorizationHandler),
authKeys: readAuthKeys(Config.authFile),
o: options,
}
mux.Head(Config.sitePath+"auth", authHandler)
mux.Head(Config.sitePath+"auth/", authHandler)
mux.Get(Config.sitePath+"auth", authHandler)
mux.Get(Config.sitePath+"auth/", authHandler)
}

mux.Post(Config.sitePath+"upload", uploadPostHandler)
Expand Down
2 changes: 1 addition & 1 deletion static/js/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Dropzone.options.dropzone = {
dropzone.cancelUpload(file)
}
};
xhr.open("HEAD", "auth/", true);
xhr.open("HEAD", "/auth", true);
xhr.send()
}
var upload = document.createElement("div");
Expand Down

0 comments on commit 773eb87

Please sign in to comment.