Skip to content

Commit

Permalink
Avoid reusing the same http.Request
Browse files Browse the repository at this point in the history
  • Loading branch information
radeksimko committed Mar 31, 2021
1 parent 487a1fa commit 3cca945
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions get_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down

0 comments on commit 3cca945

Please sign in to comment.