diff --git a/internal/httpclient/client.go b/internal/httpclient/client.go index 3da71f2..c969048 100755 --- a/internal/httpclient/client.go +++ b/internal/httpclient/client.go @@ -120,10 +120,32 @@ func (c *Client) Do(req *http.Request) (*http.Response, error) { var directStatus int if err == nil { directStatus = resp.StatusCode - if resp.StatusCode != http.StatusForbidden && resp.StatusCode != http.StatusServiceUnavailable { + // Some Cloudflare challenge pages return HTTP 200 but contain challenge + // JavaScript. Check for challenge content on any response. + if resp.StatusCode == http.StatusOK { + body, readErr := io.ReadAll(io.LimitReader(resp.Body, 32*1024)) + resp.Body.Close() + if readErr == nil && len(body) > 0 { + if isCloudflareChallenge(body) { + directStatus = http.StatusForbidden + } else { + // Not a challenge — wrap body and return + return &http.Response{ + StatusCode: resp.StatusCode, + Header: resp.Header, + Body: io.NopCloser(bytes.NewReader(body)), + ContentLength: int64(len(body)), + Request: req, + }, nil + } + } else { + return resp, nil + } + } else if resp.StatusCode != http.StatusForbidden && resp.StatusCode != http.StatusServiceUnavailable { return resp, nil + } else { + resp.Body.Close() } - resp.Body.Close() } if c.fsClient == nil {