From 54414c2bfb0a176d9c855365d4f987dfeb508e13 Mon Sep 17 00:00:00 2001 From: Evgeniy Kulikov Date: Thu, 19 Nov 2020 16:01:52 +0300 Subject: [PATCH] Fix NPE when response isn't http.Flusher Signed-off-by: Evgeniy Kulikov --- api/response.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/api/response.go b/api/response.go index cf9e1c608..6640d4cb2 100644 --- a/api/response.go +++ b/api/response.go @@ -175,9 +175,13 @@ func WriteResponse(w http.ResponseWriter, statusCode int, response []byte, mType } w.Header().Set(hdrContentLength, strconv.Itoa(len(response))) w.WriteHeader(statusCode) - if response != nil { - _, _ = w.Write(response) - w.(http.Flusher).Flush() + if response == nil { + return + } + + _, _ = w.Write(response) + if flusher, ok := w.(http.Flusher); ok { + flusher.Flush() } }