From 4d8890c2d57bac71cb614cb5484a0b21c7194151 Mon Sep 17 00:00:00 2001 From: Victor Lyuboslavsky <2685025+getvictor@users.noreply.github.com> Date: Sun, 13 Jul 2025 11:59:50 +0200 Subject: [PATCH] Fix HTTP response writing order. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In the original code, calling `Write` first implicitly calls `WriteHeader(http.StatusOK)` if `WriteHeader` hasn’t been called yet. So the HTTP status will always end up being `200 OK` --- http.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/http.go b/http.go index 54a60eb..047054f 100644 --- a/http.go +++ b/http.go @@ -55,8 +55,8 @@ func (vh VerifyHandler) ServeHTTP(rw http.ResponseWriter, inReq *http.Request) { vr, err := vh.verifier.Verify(inReq) if err != nil { // Failed to verify - rw.Write([]byte("Unauthorized")) rw.WriteHeader(http.StatusUnauthorized) + rw.Write([]byte("Unauthorized")) return }