diff --git a/src/utils/Fetcher.ts b/src/utils/Fetcher.ts index 103951b..eaa16ba 100644 --- a/src/utils/Fetcher.ts +++ b/src/utils/Fetcher.ts @@ -118,7 +118,9 @@ export class Fetcher { }; private async handleHttpCacheItem(ctx: Context, httpCacheItem: HttpCacheItem, url: URL, init?: CustomRequestInit): Promise { - if (httpCacheItem.status && httpCacheItem.status >= 200 && httpCacheItem.status <= 399) { + const triggeredCloudflareTurnstile = httpCacheItem.body.includes('cf-turnstile'); + + if (httpCacheItem.status && httpCacheItem.status >= 200 && httpCacheItem.status <= 399 && !triggeredCloudflareTurnstile) { return httpCacheItem; } @@ -126,7 +128,7 @@ export class Fetcher { throw new NotFoundError(); } - if (httpCacheItem.headers['cf-mitigated'] === 'challenge') { + if (httpCacheItem.headers['cf-mitigated'] === 'challenge' || triggeredCloudflareTurnstile) { const noFlareSolverr = init?.noFlareSolverr ?? false; const flareSolverrEndpoint = envGet('FLARESOLVERR_ENDPOINT'); if (noFlareSolverr || !flareSolverrEndpoint) {