fallback to not ranged request if server lacks HEAD

Signed-off-by: Vasiliy Tolstov <v.tolstov@selfip.ru>
This commit is contained in:
Vasiliy Tolstov 2015-06-16 01:04:48 +03:00
parent 382fa01e6f
commit d98de209cb
1 changed files with 13 additions and 7 deletions

View File

@ -215,25 +215,31 @@ func (d *HTTPDownloader) Download(dst *os.File, src *url.URL) error {
} }
resp, err := httpClient.Do(req) resp, err := httpClient.Do(req)
if err != nil || resp.StatusCode != 200 {
req.Method = "GET"
resp, err = httpClient.Do(req)
if err != nil { if err != nil {
return err return err
} }
}
req.Method = "GET"
if resp.StatusCode != 200 { if resp.StatusCode != 200 {
log.Printf( log.Printf(
"Non-200 status code: %d. Getting error body.", resp.StatusCode) "Non-200 status code: %d. Getting error body.", resp.StatusCode)
if req.Method != "GET" {
resp, err := httpClient.Do(req) req.Method = "GET"
resp, err = httpClient.Do(req)
if err != nil { if err != nil {
return err return err
} }
}
errorBody := new(bytes.Buffer) errorBody := new(bytes.Buffer)
io.Copy(errorBody, resp.Body) io.Copy(errorBody, resp.Body)
return fmt.Errorf("HTTP error '%d'! Remote side responded:\n%s", return fmt.Errorf("HTTP error '%d'! Remote side responded:\n%s",
resp.StatusCode, errorBody.String()) resp.StatusCode, errorBody.String())
} }
req.Method = "GET"
d.progress = 0 d.progress = 0
if resp.Header.Get("Accept-Ranges") == "bytes" { if resp.Header.Get("Accept-Ranges") == "bytes" {