I have a script that is designed to allow the user to invoke it again in the event that something fails, while also trying to avoid redoing work that has already been completed when that happens. As part of that:
when the script invokes curl to download a (very large) file, it use -O -C - to tell curl to resume the download if it has already been partially down loaded, or to skip it entirely if the whole thing has been downloaded;
it passes -f/--fail since I do want curl to exit with an error if it was to encounter HTTP errors such as 404.
Unfortunately, when curl tries to resume a completed download, it gets a '416 Range Not Satisfiable' HTTP error, which causes curl to exit with an error instead of skipping the completed download.
I know that curl has code to specially handle 416, but I guess it's not handling this case correctly.
Perhaps curl could make a HEAD request before trying to resume a download, and check whether the returned Content-Length matches the current size of the file. It could then completely avoid making requests with Range: bytes=<completed-length>-.
Or if that's tricky, perhaps curl could trim a byte from the end of any pre-existing file before trying to resume it, which would again avoid the 416 in the case the file was complete.
When asked to resume a download, libcurl will convert that to HTTP logic
and if then the entire file is already transferred it will result in a
416 response from the HTTP server. With CURLOPT_FAILONERRROR set in that
scenario, it should *not* lead to an error return.
Updated test 1156, added test 1273
Reported-by: Jonathan Watt