Repository navigation
fix: Do not perform a GET request (with a zero-length range) if the file is already downloaded - #14
Conversation
| d.completedLock.Lock() | ||
| skip := (d.completed == d.size) | ||
| d.completedLock.Unlock() | ||
| if skip { | ||
| return d.Error() | ||
| } |
There was a problem hiding this comment.
Is this correct? Isn't size and completed both zero the first time?
There was a problem hiding this comment.
size is the size of the remote file, it will be > 0.
There was a problem hiding this comment.
I'm wondering what happens if the server does NOT report the content-size... 🤔
There was a problem hiding this comment.
field ContentLength int64ContentLength records the length of the associated content. The value -1 indicates that the length is unknown. Unless Request.Method is "HEAD", values >= 0 indicate that the given number of bytes may be read from Body.
So, theoretically, we could also have -1 in the size field, mmmmmhhhh...
There was a problem hiding this comment.
I've pushed a fix to handle also the case with the server not providing Content-Lenght.
There are actually 4 cases:
Range= header accetpted |
Content-Len provided |
action |
|---|---|---|
| N | N | Restart from beginning (cannot use Range=...) |
| N | Y | Restart from beginning (cannot use Range=...) |
| Y | N | Restart from beginning |
| Y | Y | Resume download only if local file is smaller |
There was a problem hiding this comment.
I think that the Range= no Content-Len= is not correct. In that case you cannot resume the download because if you do a range query with a size that is the fully downloaded file, you will get a 416 Range Not Satisfiable. I think that you can safely resume only if you have both headers.
As suggested in this PR.