Skip to content

Commit

Permalink
API improvement : Drain response Body inside func HasScopes (cli#1428)
Browse files Browse the repository at this point in the history
Ensure the response body is fully read and closed to reuse the same TCPconnection.

Co-authored-by: Kumar Saurabh <[email protected]>
  • Loading branch information
itsksaurabh and Kumar Saurabh authored Jul 28, 2020
1 parent bccc93a commit 78124a9
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,13 @@ func (c Client) HasScopes(wantedScopes ...string) (bool, string, error) {
if err != nil {
return false, "", err
}
defer res.Body.Close()

defer func() {
// Ensure the response body is fully read and closed
// before we reconnect, so that we reuse the same TCPconnection.
_, _ = io.Copy(ioutil.Discard, res.Body)
res.Body.Close()
}()

if res.StatusCode != 200 {
return false, "", handleHTTPError(res)
Expand Down

0 comments on commit 78124a9

Please sign in to comment.