fix(httpclient): fix HTTP 0 status and restore FS session default

- Guard isCloudflareChallenge with directStatus >= 400 to prevent
  overriding status to 0 when no direct request was made
- When FS returns challenge page without a prior direct status,
  return an error instead of silently passing HTTP 0
- Restore default FS session ID to 'goyomi' — without a session,
  each request spawns a new Chrome, causing timeouts under load
- Add Message field to FlareSolverrResponse for better error reporting
- Document FLARESOLVERR_SESSION env var: shared session = fast after
  1st request, but serializes. Set empty for parallel (resource-heavy).
This commit is contained in:
achmad
2026-05-14 13:54:11 +07:00
parent aa697af25f
commit 6d45576790
3 changed files with 18 additions and 8 deletions
+6 -5
View File
@@ -211,12 +211,13 @@ func (c *Client) doFS(req *http.Request, directStatus int) (*http.Response, erro
}
}
// When FlareSolverr returns status 200, Chrome rendered the page.
// Check if the body actually contains Cloudflare challenge indicators
// rather than relying on structural heuristics (<pre> wrapper).
if statusCode == 200 {
if isCloudflareChallenge([]byte(rawBody)) {
// If FS returned the challenge page instead of the real content,
// reject it (HTTP 0 case when directStatus=0).
if statusCode == 200 && isCloudflareChallenge([]byte(rawBody)) {
if directStatus >= 400 {
statusCode = directStatus
} else {
return nil, fmt.Errorf("FlareSolverr returned challenge page for %s", rawURL)
}
}