From 2f4cd59ad990ac1c43a2262279e3b1bd91cd18c7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Guillot?= <fred@miniflux.net>
Date: Sun, 29 Apr 2018 23:11:10 -0700
Subject: [PATCH] Make sure to close request body in HTTP client

---
 http/client/client.go | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/http/client/client.go b/http/client/client.go
index 76630641..cba55c4d 100644
--- a/http/client/client.go
+++ b/http/client/client.go
@@ -11,6 +11,7 @@ import (
 	"encoding/json"
 	"fmt"
 	"io"
+	"io/ioutil"
 	"net"
 	"net/http"
 	"net/url"
@@ -134,13 +135,19 @@ func (c *Client) executeRequest(request *http.Request) (*Response, error) {
 
 		return nil, err
 	}
+	defer resp.Body.Close()
 
 	if resp.ContentLength > maxBodySize {
 		return nil, fmt.Errorf("client: response too large (%d bytes)", resp.ContentLength)
 	}
 
+	buf, err := ioutil.ReadAll(resp.Body)
+	if err != nil {
+		return nil, fmt.Errorf("client: error while reading body %v", err)
+	}
+
 	response := &Response{
-		Body:          resp.Body,
+		Body:          bytes.NewReader(buf),
 		StatusCode:    resp.StatusCode,
 		EffectiveURL:  resp.Request.URL.String(),
 		LastModified:  resp.Header.Get("Last-Modified"),
-- 
GitLab