fix(http): resume ranged downloads with unknown size (#1467)

This commit is contained in:
Levi authored and GitHub committed 2026-09-03 23:16:38 +08:00
1 parent 9b704f6f14
commit 3be8db664c
4 files changed
+578 -54

No files matched your search

+9 -3
View File
@@ -205,15 +205,14 @@ func isRedirectExpiredError(err error) bool {
// tryFallbackToOriginalURL attempts to make a request using the original URL
// when the redirect URL has expired. Returns the response if successful.
func (f *Fetcher) tryFallbackToOriginalURL(ctx context.Context, client *http.Client, rangeStart, rangeEnd int64, rangeRequested bool, ifRange string) (*http.Response, error) {
func (f *Fetcher) tryFallbackToOriginalURL(ctx context.Context, client *http.Client, rangeStart int64, rangeEnd *int64, rangeRequested bool, ifRange string) (*http.Response, error) {
httpReq, err := f.buildRequestWithOriginalURL(ctx, f.meta.Req)
if err != nil {
return nil, err
}
if rangeRequested {
httpReq.Header.Set(base.HttpHeaderRange,
fmt.Sprintf(base.HttpHeaderRangeFormat, rangeStart, rangeEnd))
httpReq.Header.Set(base.HttpHeaderRange, formatRangeHeader(rangeStart, rangeEnd))
if ifRange != "" {
httpReq.Header.Set(base.HttpHeaderIfRange, ifRange)
}
@@ -232,6 +231,13 @@ func (f *Fetcher) tryFallbackToOriginalURL(ctx context.Context, client *http.Cli
return resp, nil
}
func formatRangeHeader(start int64, end *int64) string {
if end == nil {
return fmt.Sprintf("bytes=%d-", start)
}
return fmt.Sprintf(base.HttpHeaderRangeFormat, start, *end)
}
// buildClient creates an HTTP client with the default connection timeout.
// Used for resolve phase where we don't have connection time data yet.
func (f *Fetcher) buildClient() *http.Client {