修复中国大陆网络环境下载镜像不成功的问题。#6
Open
ruinny wants to merge 1 commit into
Open
Conversation
ChatGPT 5 修复:
收到 — 我直接在 你原来上传的文件 基础上改了代码(拦截 Registry 返回的 S3 重定向、在需要时补上 x-amz-content-sha256 与 x-amz-date,并把初始 fetch 改为 redirect: 'manual',以便由 Worker 代为请求 S3 而不是把 307/302 转发给客户端),并把修改后的完整文件存为可下载的修复版。
我基于你上传的原文件进行了修改并保留了原 UI/逻辑:
问题根因与修复要点(简短)
原因:fetch(..., { redirect: 'follow' }) 会让 Worker 自动跟随 Registry 对象返回的 S3 重定向,导致 Worker 去请求 S3 时没有为该请求补 x-amz-content-sha256,S3 返回 Missing x-amz-content-sha256,最终 Docker 客户端收到 XML 错误。
修复:把初始请求改为 redirect: 'manual',当 Registry 返回 307/302 指向 amazonaws.com 时,Worker 自己发起到 S3 的请求并显式设置 x-amz-content-sha256(空 body 的 SHA256)和 x-amz-date,保证 S3 接收有效请求并返回正确数据。并把 token/匿名重试相关的 fetch 也改为 redirect: 'manual',以一致处理重定向。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ChatGPT 5 修复:
收到 — 我直接在 你原来上传的文件 基础上改了代码(拦截 Registry 返回的 S3 重定向、在需要时补上 x-amz-content-sha256 与 x-amz-date,并把初始 fetch 改为 redirect: 'manual',以便由 Worker 代为请求 S3 而不是把 307/302 转发给客户端),并把修改后的完整文件存为可下载的修复版。
我基于你上传的原文件进行了修改并保留了原 UI/逻辑:
问题根因与修复要点(简短)
原因:fetch(..., { redirect: 'follow' }) 会让 Worker 自动跟随 Registry 对象返回的 S3 重定向,导致 Worker 去请求 S3 时没有为该请求补 x-amz-content-sha256,S3 返回 Missing x-amz-content-sha256,最终 Docker 客户端收到 XML 错误。
修复:把初始请求改为 redirect: 'manual',当 Registry 返回 307/302 指向 amazonaws.com 时,Worker 自己发起到 S3 的请求并显式设置 x-amz-content-sha256(空 body 的 SHA256)和 x-amz-date,保证 S3 接收有效请求并返回正确数据。并把 token/匿名重试相关的 fetch 也改为 redirect: 'manual',以一致处理重定向。