Fix NPE when response isn't http.Flusher

Signed-off-by: Evgeniy Kulikov <kim@nspcc.ru>
This commit is contained in:
Evgeniy Kulikov 2020-11-19 16:01:52 +03:00
parent 54a03d3689
commit 54414c2bfb

View file

@ -175,9 +175,13 @@ func WriteResponse(w http.ResponseWriter, statusCode int, response []byte, mType
} }
w.Header().Set(hdrContentLength, strconv.Itoa(len(response))) w.Header().Set(hdrContentLength, strconv.Itoa(len(response)))
w.WriteHeader(statusCode) w.WriteHeader(statusCode)
if response != nil { if response == nil {
_, _ = w.Write(response) return
w.(http.Flusher).Flush() }
_, _ = w.Write(response)
if flusher, ok := w.(http.Flusher); ok {
flusher.Flush()
} }
} }