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:
@@ -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) {
|
func setResponseBody(w http.ResponseWriter, r *http.Request, h *model.Handler) {
|
||||||
if n, err := io.Copy(h.Writer, r.Body); err != nil {
|
if n, err := io.Copy(h.Writer, r.Body); err != nil {
|
||||||
if n > 0 {
|
if n > 0 {
|
||||||
panic("Truncated body")
|
panic(http.ErrAbortHandler)
|
||||||
}
|
}
|
||||||
httperror.ErrorJSON(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
httperror.ErrorJSON(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user