fix HTTP response body close in proxy/image.downloadImage

This commit is contained in:
Dmitry Verkhoturov
2021-05-13 18:06:20 -05:00
committed by Umputun
parent 63220f330b
commit d1ef3ff247
+1 -1
View File
@@ -159,6 +159,7 @@ func (p Image) downloadImage(ctx context.Context, imgURL string) ([]byte, error)
if err != nil {
return nil, errors.Wrapf(err, "can't download image %s", imgURL)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return nil, errors.Errorf("got unsuccessful response status %d while fetching %s", resp.StatusCode, imgURL)
@@ -168,6 +169,5 @@ func (p Image) downloadImage(ctx context.Context, imgURL string) ([]byte, error)
if err != nil {
return nil, errors.Errorf("unable to read image body")
}
_ = resp.Body.Close()
return imgData, nil
}