thibaultCha/TCBlobDownload — pull request #40 by Benjamin-Dobell (2014-10-24 16:03:11+00:00)
Title: Handle 416 status code by deleting the local file and retrying

A server returns 416 if the range we've provided to it is invalid. Whilst the local partially downloaded file exists, any attempt to retry using the same range is guaranteed to fail (unless the file is replaced on the server).

The only way to resolve the issue is to send a valid range header (unknown at this point) or not send one at all.

This patch, In response to a 416 status code, seamlessly deletes the local partially downloaded file and retries the file download. Because the local file has been deleted the retry attempt will not include a range header and hence 416 won't be returned again i.e. no infinite retrying.

If for some odd reason the local file can't be deleted then we gracefully fallback to the previous behaviour of calling the error callback with the 416 status code error.