From f5242f20ffe706d14032273ff2b64a5477ae2e1d Mon Sep 17 00:00:00 2001
From: Will McCutchen <will@mccutch.org>
Date: Sat, 15 Oct 2016 16:30:35 -0700
Subject: [PATCH] Fix basic auth handler

---
 httpbin/handlers.go      | 1 +
 httpbin/handlers_test.go | 2 ++
 2 files changed, 3 insertions(+)

diff --git a/httpbin/handlers.go b/httpbin/handlers.go
index 2073654..13754e6 100644
--- a/httpbin/handlers.go
+++ b/httpbin/handlers.go
@@ -301,6 +301,7 @@ func (h *HTTPBin) BasicAuth(w http.ResponseWriter, r *http.Request) {
 	authorized := givenUser == expectedUser && givenPass == expectedPass
 	if !authorized {
 		status = http.StatusUnauthorized
+		w.Header().Set("WWW-Authenticate", `Basic realm="Fake Realm"`)
 	}
 
 	body, _ := json.Marshal(&authResponse{
diff --git a/httpbin/handlers_test.go b/httpbin/handlers_test.go
index 4f87bc1..6698bcb 100644
--- a/httpbin/handlers_test.go
+++ b/httpbin/handlers_test.go
@@ -938,6 +938,7 @@ func TestBasicAuth(t *testing.T) {
 
 		assertStatusCode(t, w, http.StatusUnauthorized)
 		assertContentType(t, w, jsonContentType)
+		assertHeader(t, w, "WWW-Authenticate", `Basic realm="Fake Realm"`)
 
 		resp := &authResponse{}
 		json.Unmarshal(w.Body.Bytes(), resp)
@@ -959,6 +960,7 @@ func TestBasicAuth(t *testing.T) {
 
 		assertStatusCode(t, w, http.StatusUnauthorized)
 		assertContentType(t, w, jsonContentType)
+		assertHeader(t, w, "WWW-Authenticate", `Basic realm="Fake Realm"`)
 
 		resp := &authResponse{}
 		json.Unmarshal(w.Body.Bytes(), resp)
-- 
GitLab