Make server properly report that it needs authentication via HTTP

headers
This commit is contained in:
Aaron Lindsay 2013-08-29 07:36:16 -04:00
parent 9c442254a7
commit 78bfae8005

View File

@ -154,6 +154,7 @@ func putEvents(w http.ResponseWriter, r *http.Request, user *server.User) {
func eventHandler(w http.ResponseWriter, r *http.Request) { func eventHandler(w http.ResponseWriter, r *http.Request) {
user := AuthenticateUser(r) user := AuthenticateUser(r)
if user == nil { if user == nil {
w.Header().Set("WWW-Authenticate", "Basic realm=\"Asink Server\"")
apiresponse := asink.APIResponse{ apiresponse := asink.APIResponse{
Status: asink.ERROR, Status: asink.ERROR,
Explanation: "This operation requires user authentication", Explanation: "This operation requires user authentication",
@ -162,6 +163,7 @@ func eventHandler(w http.ResponseWriter, r *http.Request) {
if err != nil { if err != nil {
b = []byte(err.Error()) b = []byte(err.Error())
} }
w.WriteHeader(401)
w.Write(b) w.Write(b)
return return
} }