webGet issues a GET to url through the shared proxy/SSRF-aware client with the given extra headers (User-Agent is managed here, do not pass it). It sends a browser User-Agent by default so public CDNs (Cloudflare/Mintlify) don't bot-block it with a 403. If the response is a gateway auth challenge (4
(ctx context.Context, url string, extraHeaders map[string]string)
| 87 | // gateways allow through. An explicit CHATCLI_WEBFETCH_USER_AGENT disables the |
| 88 | // fallback, since the user chose that UA deliberately. |
| 89 | func webGet(ctx context.Context, url string, extraHeaders map[string]string) (*http.Response, error) { |
| 90 | resp, err := webGetWithUA(ctx, url, browserUA(), extraHeaders) |
| 91 | if err != nil { |
| 92 | return nil, err |
| 93 | } |
| 94 | if (resp.StatusCode == http.StatusUnauthorized || resp.StatusCode == http.StatusProxyAuthRequired) && |
| 95 | strings.TrimSpace(os.Getenv("CHATCLI_WEBFETCH_USER_AGENT")) == "" { |
| 96 | _ = resp.Body.Close() |
| 97 | return webGetWithUA(ctx, url, fallbackUserAgent, extraHeaders) |
| 98 | } |
| 99 | return resp, nil |
| 100 | } |
| 101 | |
| 102 | // webGetWithUA performs a single GET with the given User-Agent and headers. |
| 103 | // |