GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: retry webfetch with simple UA on 403 (#10328) · bpd1069/opencode@b978ca1

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages/opencode/src/tool
    • webfetch.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/opencode/src/tool/webfetch.ts‎

Copy file name to clipboardExpand all lines: packages/opencode/src/tool/webfetch.ts
+15-9Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,21 @@ export const WebFetchTool = Tool.define("webfetch", {
5656
"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8"
5757
}
5858

59-
const response = await fetch(params.url, {
60-
signal: AbortSignal.any([controller.signal, ctx.abort]),
61-
headers: {
62-
"User-Agent":
63-
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36",
64-
Accept: acceptHeader,
65-
"Accept-Language": "en-US,en;q=0.9",
66-
},
67-
})
59+
const signal = AbortSignal.any([controller.signal, ctx.abort])
60+
const headers = {
61+
"User-Agent":
62+
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36",
63+
Accept: acceptHeader,
64+
"Accept-Language": "en-US,en;q=0.9",
65+
}
66+
67+
const initial = await fetch(params.url, { signal, headers })
68+
69+
// Retry with honest UA if blocked by Cloudflare bot detection (TLS fingerprint mismatch)
70+
const response =
71+
initial.status === 403 && initial.headers.get("cf-mitigated") === "challenge"
72+
? await fetch(params.url, { signal, headers: { ...headers, "User-Agent": "opencode" } })
73+
: initial
6874

6975
clearTimeout(timeoutId)
7076

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.