1
0
Fork 0

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
1 changed files with 2 additions and 0 deletions

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