Remove TestFetcher_DownloadChunkedContinue (redundant with existing tests).
Replace TestFetcher_DownloadChunkedNotExceedSize with
TestFetcher_DownloadNoRangePauseResume which specifically targets the bug:
- Documents the root cause (non-range resume writes at accumulated offset
instead of byte 0)
- Asserts downloaded file size does not exceed source file size (the exact
bug symptom from the issue)
- Verifies file integrity via MD5
Co-authored-by: monkeyWie <[email protected]>
Remove StartTestNoRangeServer and its tests since the real bug is about
servers that don't return Content-Length at all (like GitHub's zip downloads),
not servers with Content-Length but no Range support.
The chunked tests (TestFetcher_DownloadChunkedContinue and
TestFetcher_DownloadChunkedNotExceedSize) correctly simulate the real-world
bug using StartTestCustomServer which serves files without Content-Length.
Co-authored-by: monkeyWie <[email protected]>
The go f.waitForCompletion() goroutine in expandConnections was redundant
since the downloadLoop's slow start loop already handles stateSteady by
calling waitForCompletion directly. The orphaned goroutine could race with
doStart() when writing f.ctx during pause/resume.
Co-authored-by: monkeyWie <[email protected]>
When HTTP server doesn't return Content-Length or doesn't support Range
requests, the download can accumulate extra bytes on pause/resume because:
1. Each retry/resume re-downloads from the beginning but writes at the
accumulated offset
2. No size limit enforcement for non-range downloads
3. onDownloadComplete incorrectly uses chunk.remain() for non-range
downloads, which gives negative values for chunk(0,0)
Fixes:
- Reset chunk state in downloadChunkOnce and runConnectionFallback for
non-range downloads since server will send from beginning
- Add size limit checks in download loops when Size is known
- Fix onDownloadComplete to use conn.Completed for non-range downloads
instead of unreliable chunk.remain()
- Add test cases for non-range download, pause/resume, and size limit
Co-authored-by: monkeyWie <[email protected]>