fix: panic sentinel value if http client misbehaves

When an http client does not consume the whole body, we panic'ed a
custom message instead of the required sentinel value.

For the details, check ¹ and look for ErrAbortHandler.

¹: https://pkg.go.dev/net/http

Co-authored-by: César Gallego Rodríguez <gallego.cesar@gmail.com>
This commit is contained in:
pancho horrillo
2020-05-11 13:59:09 +02:00
parent 35376a407b
commit 13adcc37b6
+1 -1
View File
@@ -193,7 +193,7 @@ func setResponseCookies(w http.ResponseWriter, r *http.Request, h *model.Handler
func setResponseBody(w http.ResponseWriter, r *http.Request, h *model.Handler) {
if n, err := io.Copy(h.Writer, r.Body); err != nil {
if n > 0 {
panic("Truncated body")
panic(http.ErrAbortHandler)
}
httperror.ErrorJSON(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
}