From 28095cf027d1904f7af6dea2390c86228c2102ed Mon Sep 17 00:00:00 2001 From: Giovanni Tirloni Date: Wed, 13 Jun 2018 20:30:19 -0300 Subject: [PATCH] Do not return error on initial HEAD request --- common/download.go | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/common/download.go b/common/download.go index 9d2fa45f4..59d882b50 100644 --- a/common/download.go +++ b/common/download.go @@ -278,8 +278,9 @@ func (d *HTTPDownloader) Download(dst *os.File, src *url.URL) error { } resp, err := httpClient.Do(req) - if err == nil { - + if err != nil { + log.Printf("[DEBUG] (download) Error making HTTP HEAD request: %s", err.Error()) + } else { if resp.StatusCode >= 200 && resp.StatusCode < 300 { // If the HEAD request succeeded, then attempt to set the range // query if we can. @@ -292,13 +293,9 @@ func (d *HTTPDownloader) Download(dst *os.File, src *url.URL) error { } } } + } else { + log.Printf("[DEBUG] (download) Unexpected HTTP response during HEAD request: %s", resp.Status) } - - if resp.StatusCode >= 400 && resp.StatusCode < 600 { - return fmt.Errorf("Received HTTP error: %s", resp.Status) - } - } else { - return err } // Set the request to GET now, and redo the query to download @@ -307,8 +304,10 @@ func (d *HTTPDownloader) Download(dst *os.File, src *url.URL) error { resp, err = httpClient.Do(req) if err != nil { return err - } else if err != nil || (resp.StatusCode >= 400 && resp.StatusCode < 600) { - return fmt.Errorf("%s", resp.Status) + } else { + if resp.StatusCode >= 400 && resp.StatusCode < 600 { + return fmt.Errorf("Error making HTTP GET request: %s", resp.Status) + } } d.total = d.current + uint64(resp.ContentLength)