From 39c3f460062a7641243b2c5da3069d296c21c59f Mon Sep 17 00:00:00 2001 From: HuKeping Date: Tue, 29 Mar 2016 21:18:07 +0800 Subject: [PATCH] Tiny refactor It is a little wired to use "err.ServeHTTP". Via the sample from docker/distribution, we can use "challenge" as the variable name here. Signed-off-by: Hu Keping --- utils/http.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/utils/http.go b/utils/http.go index d9a1357972..95245d9fb2 100644 --- a/utils/http.go +++ b/utils/http.go @@ -64,8 +64,10 @@ func (root *rootHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { var authCtx context.Context var err error if authCtx, err = root.auth.Authorized(ctx, access...); err != nil { - if err, ok := err.(auth.Challenge); ok { - err.ServeHTTP(w, r) + if challenge, ok := err.(auth.Challenge); ok { + // Let the challenge write the response. + challenge.ServeHTTP(w, r) + w.WriteHeader(http.StatusUnauthorized) return }