Merge pull request #35 from nspcc-dev/fix-api-response

Fix NPE when response isn't http.Flusher
This commit is contained in:
Evgeniy Kulikov 2020-11-23 12:45:48 +03:00 committed by GitHub
commit 208c45a713

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 {
return
}
_, _ = w.Write(response) _, _ = w.Write(response)
w.(http.Flusher).Flush() if flusher, ok := w.(http.Flusher); ok {
flusher.Flush()
} }
} }