reg
reg copied to clipboard
TokenTransport may cause amount of ESTABLISHED connections
The unused resp.Body should be Close() and read , or http.Client will make many new connections.
I think it should like
func (t *TokenTransport) RoundTrip(req *http.Request) (*http.Response, error) {
resp, err := t.Transport.RoundTrip(req)
if err != nil {
return resp, err
}
authService, err := isTokenDemand(resp)
if err != nil {
defer resp.Body.Close()
io.Copy(ioutil.Discard,resp.Body)
return nil, err
}
if authService == nil {
return resp, nil
}
defer resp.Body.Close()
io.Copy(ioutil.Discard,resp.Body)
return t.authAndRetry(authService, req)
}
want to make a PR, thanks!
I’m glad to,will make some days later.