From 3a542054fc99dfeaaad314b797f6d1f562189689 Mon Sep 17 00:00:00 2001 From: Tracey Lesley <45711711+MrGlp@users.noreply.github.com> Date: Sun, 14 Jan 2024 09:58:14 +0800 Subject: [PATCH] fix: compatible with not follow the http range response standard --- internal/protocol/http/fetcher.go | 5 +++-- pkg/base/constants.go | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) 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" )