Skip to content

Commit

Permalink
Compatible with http site redirection parsing resource size 6
Browse files Browse the repository at this point in the history
  • Loading branch information
dcguo committed Jan 13, 2024
1 parent 895a8d2 commit 236176a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 3 additions & 2 deletions internal/protocol/http/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,15 @@ 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)) {
// 1.返回206响应码表示支持断点下载 2.不返回206但是Accept-Ranges首部并且等于bytes也表示支持断点下载
res.Range = true
// 解析资源大小: bytes 0-1000/1001 => 1001
contentTotal := path.Base(httpResp.Header.Get(base.HttpHeaderContentRange))
if contentTotal != "" {
parse, err := strconv.ParseInt(contentTotal, 10, 64)
if err != nil {
err = errors.New(contentTotal)
return err
}
res.Size = parse
Expand Down
2 changes: 2 additions & 0 deletions pkg/base/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

0 comments on commit 236176a

Please sign in to comment.