all: call Close() after reading http.Response.Body

As the doc of http.Response.Body says:

// The http Client and Transport guarantee that Body is always
// non-nil, even on responses without a body or responses with
// a zero-length body. It is the caller's responsibility to
// close Body.

Signed-off-by: Jes Cok <xigua67damn@gmail.com>
This commit is contained in:
Jes Cok 2024-03-21 22:09:26 +08:00
parent 9359aef3e3
commit bc31162cc2
2 changed files with 2 additions and 0 deletions

View File

@ -69,6 +69,7 @@ func write(key string, value string, version int64) error {
if err != nil {
log.Fatalf("failed to read request body: %s", err)
}
httpResp.Body.Close()
resp := new(response)
err = json.Unmarshal(respBytes, resp)

View File

@ -103,6 +103,7 @@ func TestNewPeerHandlerOnRaftPrefix(t *testing.T) {
if err != nil {
t.Fatalf("unexpected io.ReadAll error: %v", err)
}
resp.Body.Close()
if w := "test data"; string(body) != w {
t.Errorf("#%d: body = %s, want %s", i, body, w)
}