diff --git a/README.md b/README.md index 592628a..5fbdf2a 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ -# thinIRC +# Gocirc a lightweight IRC server written in Golang \ No newline at end of file diff --git a/http.go b/http.go index 16f1c2f..7c9d1d5 100644 --- a/http.go +++ b/http.go @@ -33,6 +33,7 @@ func startHTTP(cfg Config) { func handleKick(w http.ResponseWriter, r *http.Request) { user, pass, ok := r.BasicAuth() if !ok || !checkCredentials(user, pass) || !globalOps[user] { + w.Header().Set("WWW-Authenticate", `Basic realm="API"`) http.Error(w, "Unauthorized", http.StatusUnauthorized) return } @@ -88,6 +89,7 @@ func handleKick(w http.ResponseWriter, r *http.Request) { func handleModeAPI(w http.ResponseWriter, r *http.Request) { user, pass, ok := r.BasicAuth() if !ok || !checkCredentials(user, pass) || !globalOps[user] { + w.Header().Set("WWW-Authenticate", `Basic realm="API"`) http.Error(w, "Unauthorized", http.StatusUnauthorized) return } @@ -142,7 +144,9 @@ func handleModeAPI(w http.ResponseWriter, r *http.Request) { Status: "ok", } w.Header().Set("Content-Type", "application/json") - json.NewEncoder(w).Encode(resp) + enc := json.NewEncoder(w) + enc.SetIndent(" ", " ") + enc.Encode(resp) } type ChannelInfo struct { @@ -154,6 +158,7 @@ type ChannelInfo struct { func handleListAPI(w http.ResponseWriter, r *http.Request) { user, pass, ok := r.BasicAuth() if !ok || !checkCredentials(user, pass) || !globalOps[user] { + w.Header().Set("WWW-Authenticate", `Basic realm="API"`) http.Error(w, "Unauthorized", http.StatusUnauthorized) return } @@ -177,13 +182,16 @@ func handleListAPI(w http.ResponseWriter, r *http.Request) { } w.Header().Set("Content-Type", "application/json") - if err := json.NewEncoder(w).Encode(list); err != nil { + enc := json.NewEncoder(w) + enc.SetIndent(" ", " ") + if err := enc.Encode(list); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) } } func handleMOTDreload(w http.ResponseWriter, r *http.Request) { user, pass, ok := r.BasicAuth() if !ok || !checkCredentials(user, pass) || !globalOps[user] { + w.Header().Set("WWW-Authenticate", `Basic realm="API"`) http.Error(w, "Unauthorized", http.StatusUnauthorized) return }