fix: restore adaptive HTTP (direct first, FS fallback) with session
Re-enables the direct-then-FS approach removed earlier due to TLS fingerprint mismatch. With FS sessions configured, the fallback path is fast after the first request per domain (Chrome caches cf_clearance). Non-Cloudflare sites still benefit from direct HTTP speed.
This commit is contained in:
@@ -45,6 +45,7 @@ services:
|
|||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
environment:
|
environment:
|
||||||
LOG_LEVEL: ${FLARESOLVERR_LOG_LEVEL}
|
LOG_LEVEL: ${FLARESOLVERR_LOG_LEVEL}
|
||||||
|
# FLARESOLVERR_SESSION: ${FLARESOLVERR_SESSION:-goyomi}
|
||||||
ports:
|
ports:
|
||||||
- "8191:8191"
|
- "8191:8191"
|
||||||
networks:
|
networks:
|
||||||
|
|||||||
@@ -122,36 +122,29 @@ func (c *Client) Do(req *http.Request) (*http.Response, error) {
|
|||||||
req.Header.Set("User-Agent", c.userAgent)
|
req.Header.Set("User-Agent", c.userAgent)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Always route through FlareSolverr when configured. Go's TLS fingerprint
|
// Try direct first. Most sites don't have Cloudflare, so this is fast.
|
||||||
// doesn't match Chrome's, so Cloudflare clearance cookies from FS are
|
// For Cloudflare sites, Go's TLS fingerprint doesn't match Chrome's, so
|
||||||
// rejected by Go's net/http — meaning every direct request gets challenged
|
// the direct request gets 403 — fall back to FlareSolverr. FS uses a
|
||||||
// again. FS Chrome caches the clearance internally, so subsequent calls
|
// persistent session (Chrome caches cf_clearance), so only the first
|
||||||
// for the same domain are near-instant.
|
// FS request per domain solves the challenge; subsequent ones are fast.
|
||||||
//
|
resp, err := c.doDirect(req)
|
||||||
// When FS is not configured, fall back to direct HTTP.
|
var directStatus int
|
||||||
if c.fsClient != nil {
|
if err == nil {
|
||||||
return c.doFS(req, 0)
|
directStatus = resp.StatusCode
|
||||||
|
if resp.StatusCode != http.StatusForbidden && resp.StatusCode != http.StatusServiceUnavailable {
|
||||||
|
return resp, nil
|
||||||
|
}
|
||||||
|
resp.Body.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- direct-first path (commented out — see TLS fingerprint issue above) ---
|
if c.fsClient == nil {
|
||||||
// resp, err := c.doDirect(req)
|
if err != nil {
|
||||||
// var directStatus int
|
return nil, err
|
||||||
// if err == nil {
|
}
|
||||||
// directStatus = resp.StatusCode
|
return nil, fmt.Errorf("HTTP %d (challenge detected but FlareSolverr not configured)", resp.StatusCode)
|
||||||
// if resp.StatusCode != http.StatusForbidden && resp.StatusCode != http.StatusServiceUnavailable {
|
}
|
||||||
// return resp, nil
|
|
||||||
// }
|
|
||||||
// resp.Body.Close()
|
|
||||||
// }
|
|
||||||
// if c.fsClient == nil {
|
|
||||||
// if err != nil {
|
|
||||||
// return nil, err
|
|
||||||
// }
|
|
||||||
// return nil, fmt.Errorf("HTTP %d (challenge detected but FlareSolverr not configured)", resp.StatusCode)
|
|
||||||
// }
|
|
||||||
// return c.doFS(req, directStatus)
|
|
||||||
|
|
||||||
return c.doDirect(req)
|
return c.doFS(req, directStatus)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) doDirect(req *http.Request) (*http.Response, error) {
|
func (c *Client) doDirect(req *http.Request) (*http.Response, error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user