diff --git a/internal/protocol/http/fetcher.go b/internal/protocol/http/fetcher.go index 15fc3119..8f7d03ed 100644 --- a/internal/protocol/http/fetcher.go +++ b/internal/protocol/http/fetcher.go @@ -18,6 +18,7 @@ import ( "os" "path" "strconv" + "strings" "time" ) @@ -104,8 +105,8 @@ func (f *Fetcher) Resolve(req *base.Request) error { Range: false, Files: []*base.FileInfo{}, } - if base.HttpCodePartialContent == httpResp.StatusCode { - // 返回206响应码表示支持断点下载 + if base.HttpCodePartialContent == httpResp.StatusCode || (base.HttpCodeOK == httpResp.StatusCode && httpResp.Header.Get(base.HttpHeaderAcceptRanges) == base.HttpHeaderBytes && strings.HasPrefix(httpResp.Header.Get(base.HttpHeaderContentRange), base.HttpHeaderBytes)) { + // 1.返回206响应码表示支持断点下载 2.不返回206但是Accept-Ranges首部并且等于bytes也表示支持断点下载 res.Range = true // 解析资源大小: bytes 0-1000/1001 => 1001 contentTotal := path.Base(httpResp.Header.Get(base.HttpHeaderContentRange)) diff --git a/pkg/base/constants.go b/pkg/base/constants.go index cb57b02f..ee78e807 100644 --- a/pkg/base/constants.go +++ b/pkg/base/constants.go @@ -16,10 +16,12 @@ const ( HttpCodePartialContent = 206 HttpHeaderRange = "Range" + HttpHeaderAcceptRanges = "Accept-Ranges" HttpHeaderContentLength = "Content-Length" HttpHeaderContentRange = "Content-Range" HttpHeaderContentDisposition = "Content-Disposition" HttpHeaderUserAgent = "Usr-Agent" + HttpHeaderBytes = "bytes" HttpHeaderRangeFormat = "bytes=%d-%d" )