use default HTTP client to download blob from redirect URL

This commit is contained in:
rhysd 2018-01-19 17:00:30 +09:00
parent d98ca18787
commit 996452a5ed
1 changed files with 7 additions and 2 deletions

View File

@ -35,13 +35,18 @@ func (up *Updater) downloadDirectlyFromURL(assetURL string) (io.ReadCloser, erro
}
req.Header.Add("Accept", "application/octet-stream")
res, err := up.httpClient.Do(req)
req = req.WithContext(up.apiCtx)
// OAuth HTTP client is not available to download blob from URL when the URL is a redirect URL
// returned from GitHub Releases API (response status 400).
// Use default HTTP client instead.
res, err := http.DefaultClient.Do(req)
if err != nil {
return nil, fmt.Errorf("Failed to download a release file from %s: %s", assetURL, err)
}
if res.StatusCode != 200 {
return nil, fmt.Errorf("Failed to download a release file from %s", assetURL)
return nil, fmt.Errorf("Failed to download a release file from %s: Not successfull status %d", assetURL, res.StatusCode)
}
return res.Body, nil