Skip to content

Commit 78124a9

Browse files
itsksaurabhKumar Saurabh
andauthored
API improvement : Drain response Body inside func HasScopes (cli#1428)
Ensure the response body is fully read and closed to reuse the same TCPconnection. Co-authored-by: Kumar Saurabh <kumarsaurabh@Kumars-MacBook-Air.local>
1 parent bccc93a commit 78124a9

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

api/client.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,13 @@ func (c Client) HasScopes(wantedScopes ...string) (bool, string, error) {
212212
if err != nil {
213213
return false, "", err
214214
}
215-
defer res.Body.Close()
215+
216+
defer func() {
217+
// Ensure the response body is fully read and closed
218+
// before we reconnect, so that we reuse the same TCPconnection.
219+
_, _ = io.Copy(ioutil.Discard, res.Body)
220+
res.Body.Close()
221+
}()
216222

217223
if res.StatusCode != 200 {
218224
return false, "", handleHTTPError(res)

0 commit comments

Comments
 (0)