Commit d98de209 authored by Vasiliy Tolstov's avatar Vasiliy Tolstov

fallback to not ranged request if server lacks HEAD

Signed-off-by: default avatarVasiliy Tolstov <v.tolstov@selfip.ru>
parent 382fa01e
...@@ -215,18 +215,23 @@ func (d *HTTPDownloader) Download(dst *os.File, src *url.URL) error { ...@@ -215,18 +215,23 @@ func (d *HTTPDownloader) Download(dst *os.File, src *url.URL) error {
} }
resp, err := httpClient.Do(req) resp, err := httpClient.Do(req)
if err != nil { if err != nil || resp.StatusCode != 200 {
return err req.Method = "GET"
resp, err = httpClient.Do(req)
if err != nil {
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"
if err != nil { resp, err = httpClient.Do(req)
return err if err != nil {
return err
}
} }
errorBody := new(bytes.Buffer) errorBody := new(bytes.Buffer)
io.Copy(errorBody, resp.Body) io.Copy(errorBody, resp.Body)
...@@ -234,6 +239,7 @@ func (d *HTTPDownloader) Download(dst *os.File, src *url.URL) error { ...@@ -234,6 +239,7 @@ func (d *HTTPDownloader) Download(dst *os.File, src *url.URL) error {
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" {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment