From 82c8d53bf0f6d7aa44c931704022b6c61d606ed3 Mon Sep 17 00:00:00 2001 From: Koala Yeung Date: Tue, 13 Oct 2020 12:19:15 +0800 Subject: [PATCH] authorizer: Improve error handle to response pipe error * Properly handle and report the response pipe error. --- authorizer.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/authorizer.go b/authorizer.go index 28aabfc..4de63db 100644 --- a/authorizer.go +++ b/authorizer.go @@ -99,7 +99,12 @@ func (ar Authorizer) Wrap(inner http.Handler) http.Handler { ew := new(bytes.Buffer) rw := httptest.NewRecorder() // FIXME: should do this without httptest - resp.WriteTo(rw, ew) + if err = resp.WriteTo(rw, ew); err != nil { + log.Printf("cannot write to response pipe: %s", err) + w.WriteHeader(http.StatusInternalServerError) + fmt.Fprintf(w, http.StatusText(http.StatusInternalServerError)) + return + } // if code is not http.StatusOK (200) if rw.Code != http.StatusOK {