Skip to content

fix: resolve CDN redirect before Range requests (5.0.2)#15

Merged
AthrunArthur merged 1 commit into
YeeZTech:mainfrom
freeof123:fix/fetch-range-cross-origin-redirect
Jun 22, 2026
Merged

fix: resolve CDN redirect before Range requests (5.0.2)#15
AthrunArthur merged 1 commit into
YeeZTech:mainfrom
freeof123:fix/fetch-range-cross-origin-redirect

Conversation

@freeof123

Copy link
Copy Markdown
Member

概述

  • 修复 v5.0.1 在 CDN 跨域 302 重定向场景下下载失败的问题,报错为 ERR_CANNOT_READ_TAIL,HTTP 状态码为 0(例如 cdn1.dianshudata.comcs-test.dianshudata.com)。
  • v5.0.1 在 fetchRange 中使用 redirect: 'manual',意图在重定向时重新携带 Range 头(Safari 兼容)。但跨域 302 时浏览器返回 opaque redirectstatus === 0),JS 无法读取 Location,手动跟跳失效。
  • 修复思路: 先用 HEAD + redirect: 'follow' 跟完重定向,取 response.url 作为真实文件地址,再对该地址直接发 Range(Range 请求不再经过重定向)。Chrome/Firefox 可恢复正常,Safari 也不会在跟跳时丢失 Range

改动

  • fetchRange.js:移除 manual 重定向循环,改回 redirect: 'follow';新增 resolvedFetchUrl()
  • downloadUnsealed.js / HttpSealedFileStream.js:用 headResp.url 作为后续 Range 请求 URL
  • 版本号升至 5.0.2

测试

  • 本地复现 cdn1.dianshudata.com/…sealed:v5.0.1 报 HTTP 0,本分支下载成功
  • npm run build 通过
  • 确认 Safari 在 CDN 跨域重定向场景下仍可正常下载
  • 发布 5.0.2 后更新宿主项目(dianshu-website、SSR)

5.0.1 used redirect:'manual' to re-apply Range on redirects, but cross-origin
302 responses are opaque (HTTP status 0) so Location cannot be read. Resolve the
final URL via HEAD response.url first, then issue Range against that URL directly.

Co-authored-by: Cursor <cursoragent@cursor.com>
@AthrunArthur AthrunArthur merged commit 9ff18d7 into YeeZTech:main Jun 22, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants