Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion remote_fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ func defaultRemoteFetchStrategy(remoteFetchHost string, versionStrategy VersionS

shaDownloadURL := fmt.Sprintf("%s.sha256", jarDownloadURL)
shaDownloadResponse, err := http.Get(shaDownloadURL)

if err != nil {
return fmt.Errorf("download sha256 from %s failed: %w", shaDownloadURL, err)
}
defer closeBody(shaDownloadResponse)()

if err == nil && shaDownloadResponse.StatusCode == http.StatusOK {
Expand All @@ -68,6 +70,9 @@ func defaultRemoteFetchStrategy(remoteFetchHost string, versionStrategy VersionS

func closeBody(resp *http.Response) func() {
return func() {
if resp == nil || resp.Body == nil {
return
}
if err := resp.Body.Close(); err != nil {
log.Fatal(err)
}
Expand Down
6 changes: 6 additions & 0 deletions remote_fetch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,3 +417,9 @@ func Test_defaultRemoteFetchStrategy_whenContentLengthNotSet(t *testing.T) {
assert.NoError(t, err)
assert.FileExists(t, cacheLocation)
}

func Test_closeBody_NilResponse(t *testing.T) {
assert.NotPanics(t, func() {
closeBody(nil)()
})
}