From 3cca945b8b947e79d3ea1fc653e251c6670f8e4b Mon Sep 17 00:00:00 2001 From: Radek Simko Date: Wed, 31 Mar 2021 09:09:04 +0100 Subject: [PATCH] Avoid reusing the same http.Request --- get_http.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/get_http.go b/get_http.go index b0229d763..8c2278d6a 100644 --- a/get_http.go +++ b/get_http.go @@ -181,7 +181,6 @@ func (g *HttpGetter) GetFile(dst string, src *url.URL) error { if fi, err := f.Stat(); err == nil { if _, err = f.Seek(0, io.SeekEnd); err == nil { currentFileSize = fi.Size() - req.Header.Set("Range", fmt.Sprintf("bytes=%d-", currentFileSize)) if currentFileSize >= headResp.ContentLength { // file already present return nil @@ -191,7 +190,17 @@ func (g *HttpGetter) GetFile(dst string, src *url.URL) error { } } } - req.Method = "GET" + + req, err = http.NewRequest("GET", src.String(), nil) + if err != nil { + return err + } + if g.Header != nil { + req.Header = g.Header.Clone() + } + if currentFileSize > 0 { + req.Header.Set("Range", fmt.Sprintf("bytes=%d-", currentFileSize)) + } resp, err := g.Client.Do(req) if err != nil {