From fadaefeaef2bfa54d23997e39701f02698cfde67 Mon Sep 17 00:00:00 2001 From: arkon Date: Mon, 11 Oct 2021 16:12:26 -0400 Subject: [PATCH] Handle HTTP 403 responses with CloudflareInterceptor Based on https://github.com/jmir1/aniyomi/commit/8d34da591ed8e4341f0f8312402164a7bc17bc68 Co-authored-by: jmir1 --- .../tachiyomi/network/interceptor/CloudflareInterceptor.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/network/interceptor/CloudflareInterceptor.kt b/app/src/main/java/eu/kanade/tachiyomi/network/interceptor/CloudflareInterceptor.kt index 05ee87a786..f15d598ab6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/network/interceptor/CloudflareInterceptor.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/network/interceptor/CloudflareInterceptor.kt @@ -56,7 +56,7 @@ class CloudflareInterceptor(private val context: Context) : Interceptor { val response = chain.proceed(originalRequest) // Check if Cloudflare anti-bot is on - if (response.code != 503 || response.header("Server") !in SERVER_CHECK) { + if (response.code !in ERROR_CODES || response.header("Server") !in SERVER_CHECK) { return response } @@ -127,7 +127,7 @@ class CloudflareInterceptor(private val context: Context) : Interceptor { isMainFrame: Boolean ) { if (isMainFrame) { - if (errorCode == 503) { + if (errorCode in ERROR_CODES) { // Found the Cloudflare challenge page. challengeFound = true } else { @@ -167,6 +167,7 @@ class CloudflareInterceptor(private val context: Context) : Interceptor { } companion object { + private val ERROR_CODES = listOf(403, 503) private val SERVER_CHECK = arrayOf("cloudflare-nginx", "cloudflare") private val COOKIE_NAMES = listOf("cf_clearance") }