From d98de209cb8b38b8d93c30f93f946c59b93ea24d Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Tue, 16 Jun 2015 01:04:48 +0300 Subject: [PATCH] fallback to not ranged request if server lacks HEAD Signed-off-by: Vasiliy Tolstov --- common/download.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/common/download.go b/common/download.go index d6711b6b4..782712e94 100644 --- a/common/download.go +++ b/common/download.go @@ -215,18 +215,23 @@ func (d *HTTPDownloader) Download(dst *os.File, src *url.URL) error { } resp, err := httpClient.Do(req) - if err != nil { - return err + if err != nil || resp.StatusCode != 200 { + req.Method = "GET" + resp, err = httpClient.Do(req) + if err != nil { + return err + } } - req.Method = "GET" if resp.StatusCode != 200 { log.Printf( "Non-200 status code: %d. Getting error body.", resp.StatusCode) - - resp, err := httpClient.Do(req) - if err != nil { - return err + if req.Method != "GET" { + req.Method = "GET" + resp, err = httpClient.Do(req) + if err != nil { + return err + } } errorBody := new(bytes.Buffer) io.Copy(errorBody, resp.Body) @@ -234,6 +239,7 @@ func (d *HTTPDownloader) Download(dst *os.File, src *url.URL) error { resp.StatusCode, errorBody.String()) } + req.Method = "GET" d.progress = 0 if resp.Header.Get("Accept-Ranges") == "bytes" {