From 9672298fa8d8fc680aaa634d8cc03e06cf0cf2ce Mon Sep 17 00:00:00 2001 From: Kevin Wan Date: Sun, 22 Aug 2021 09:27:20 +0800 Subject: [PATCH] make sure setting code happen before callback in rest (#936) --- rest/handler/authhandler.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/rest/handler/authhandler.go b/rest/handler/authhandler.go index 16289961..14dd7e7f 100644 --- a/rest/handler/authhandler.go +++ b/rest/handler/authhandler.go @@ -112,11 +112,12 @@ func unauthorized(w http.ResponseWriter, r *http.Request, err error, callback Un } else { detailAuthLog(r, noDetailReason) } + + writer.WriteHeader(http.StatusUnauthorized) + if callback != nil { callback(writer, r, err) } - - writer.WriteHeader(http.StatusUnauthorized) } type guardedResponseWriter struct {