From 26a9cf49117bb54ca61c119a1570afdb31bd973c Mon Sep 17 00:00:00 2001 From: Bennett Wetters Date: Sat, 4 Nov 2023 22:30:39 +0100 Subject: [PATCH] Actually set the response status correctly Reading the docs helps. --- main.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 9d91479..f1916a5 100644 --- a/main.go +++ b/main.go @@ -41,8 +41,8 @@ func main() { http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { if r.Method != http.MethodGet { log.Println("Wrong METHOD from", r.RemoteAddr) - w.WriteHeader(http.StatusMethodNotAllowed) w.Header().Set("allow", http.MethodGet) + w.WriteHeader(http.StatusMethodNotAllowed) return } @@ -61,15 +61,15 @@ func main() { username, password, ok := r.BasicAuth() if !ok || username != validUsername || password != validPassword { log.Println("Unauthorized request from", r.RemoteAddr) - w.WriteHeader(http.StatusUnauthorized) w.Header().Set("www-authentication", "Basic realm=\"space-api\"") + w.WriteHeader(http.StatusUnauthorized) return } if r.Method != http.MethodPut { log.Println("Wrong METHOD from", r.RemoteAddr) - w.WriteHeader(http.StatusMethodNotAllowed) w.Header().Set("allow", http.MethodPut) + w.WriteHeader(http.StatusMethodNotAllowed) return }