closeResponse close non nil response with any response Body. convenient wrapper to drain any remaining data on response body. Subsequently this allows golang http RoundTripper to re-use the same connection for future requests.
(resp *http.Response)
| 128 | // Subsequently this allows golang http RoundTripper |
| 129 | // to re-use the same connection for future requests. |
| 130 | func closeResponse(resp *http.Response) { |
| 131 | // Callers should close resp.Body when done reading from it. |
| 132 | // If resp.Body is not closed, the Client's underlying RoundTripper |
| 133 | // (typically Transport) may not be able to re-use a persistent TCP |
| 134 | // connection to the server for a subsequent "keep-alive" request. |
| 135 | if resp != nil && resp.Body != nil { |
| 136 | // Drain any remaining Body and then close the connection. |
| 137 | // Without this closing connection would disallow re-using |
| 138 | // the same connection for future uses. |
| 139 | // - http://stackoverflow.com/a/17961593/4465767 |
| 140 | io.Copy(io.Discard, resp.Body) |
| 141 | resp.Body.Close() |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | func getAssumeRoleCredentials(clnt *http.Client, endpoint string, opts STSAssumeRoleOptions) (AssumeRoleResponse, error) { |
| 146 | v := url.Values{} |
no test coverage detected