From 466070b0580728e63bd1a415e0019639e55d7148 Mon Sep 17 00:00:00 2001 From: Sander van Harmelen Date: Wed, 7 Dec 2016 10:37:23 +0100 Subject: [PATCH] Make GetArchiveLink behave the same as other calls MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit All available calls in the `go-github` package close the `resp.Body` before returning. Because the `GetArchiveLink` method doesn’t use the [`Do`](https://github.com/google/go-github/blob/master/github/github.go#L381) method, we have to make sure the body is closed here as well. Closes #485. Change-Id: Iec0d88cf66d4d658fcd6aec374b4bc2358269a09 --- github/repos_contents.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/github/repos_contents.go b/github/repos_contents.go index ebf4d04..7b08cf0 100644 --- a/github/repos_contents.go +++ b/github/repos_contents.go @@ -267,8 +267,12 @@ func (s *RepositoriesService) GetArchiveLink(owner, repo string, archiveformat a } else { resp, err = s.client.client.Transport.RoundTrip(req) } - if err != nil || resp.StatusCode != http.StatusFound { - return nil, newResponse(resp), err + if err != nil { + return nil, nil, err + } + resp.Body.Close() + if resp.StatusCode != http.StatusFound { + return nil, newResponse(resp), fmt.Errorf("unexpected status code: %s", resp.Status) } parsedURL, err := url.Parse(resp.Header.Get("Location")) return parsedURL, newResponse(resp), err