Skip to content

Commit c5b0f21

Browse files
authored
Clean up connection reuse code inside Do func
Fixes #1646 .
1 parent 1e6d9a5 commit c5b0f21

1 file changed

Lines changed: 1 addition & 14 deletions

File tree

‎github/github.go‎

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -556,20 +556,7 @@ func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) (*Res
556556
return nil, err
557557
}
558558

559-
defer func() {
560-
// Ensure the response body is fully read and closed
561-
// before we reconnect, so that we reuse the same TCP connection.
562-
// Close the previous response's body. But read at least some of
563-
// the body so if it's small the underlying TCP connection will be
564-
// re-used. No need to check for errors: if it fails, the Transport
565-
// won't reuse it anyway.
566-
const maxBodySlurpSize = 2 << 10
567-
if resp.ContentLength == -1 || resp.ContentLength <= maxBodySlurpSize {
568-
io.CopyN(ioutil.Discard, resp.Body, maxBodySlurpSize)
569-
}
570-
571-
resp.Body.Close()
572-
}()
559+
defer resp.Body.Close()
573560

574561
response := newResponse(resp)
575562

0 commit comments

Comments
 (0)