diff options
| author | Fynn <[email protected]> | 2026-01-24 13:14:32 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-01-24 00:14:32 -0500 |
| commit | b978ca11da89209900931ca0c31fd9e769b98f78 (patch) | |
| tree | fcdebfe87f156b0e66426b6d418168bfe77a771f | |
| parent | e452b3cae04d4c498f7c4b61bfa2f71ff799109c (diff) | |
| download | opencode-b978ca11da89209900931ca0c31fd9e769b98f78.tar.gz opencode-b978ca11da89209900931ca0c31fd9e769b98f78.zip | |
fix: retry webfetch with simple UA on 403 (#10328)
| -rw-r--r-- | packages/opencode/src/tool/webfetch.ts | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/packages/opencode/src/tool/webfetch.ts b/packages/opencode/src/tool/webfetch.ts index e592caac2..a4a54598c 100644 --- a/packages/opencode/src/tool/webfetch.ts +++ b/packages/opencode/src/tool/webfetch.ts @@ -56,15 +56,21 @@ export const WebFetchTool = Tool.define("webfetch", { "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8" } - const response = await fetch(params.url, { - signal: AbortSignal.any([controller.signal, ctx.abort]), - headers: { - "User-Agent": - "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36", - Accept: acceptHeader, - "Accept-Language": "en-US,en;q=0.9", - }, - }) + const signal = AbortSignal.any([controller.signal, ctx.abort]) + const headers = { + "User-Agent": + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36", + Accept: acceptHeader, + "Accept-Language": "en-US,en;q=0.9", + } + + const initial = await fetch(params.url, { signal, headers }) + + // Retry with honest UA if blocked by Cloudflare bot detection (TLS fingerprint mismatch) + const response = + initial.status === 403 && initial.headers.get("cf-mitigated") === "challenge" + ? await fetch(params.url, { signal, headers: { ...headers, "User-Agent": "opencode" } }) + : initial clearTimeout(timeoutId) |
