From 4bbf78e840bd28c1024b2726c98dd641a1e3006e Mon Sep 17 00:00:00 2001 From: inorichi Date: Thu, 5 Apr 2018 11:58:28 +0200 Subject: [PATCH] Don't send cache control with cloudflare challenge --- .../eu/kanade/tachiyomi/network/CloudflareInterceptor.kt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/network/CloudflareInterceptor.kt b/app/src/main/java/eu/kanade/tachiyomi/network/CloudflareInterceptor.kt index dae1252c2c..1a41d117f5 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/network/CloudflareInterceptor.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/network/CloudflareInterceptor.kt @@ -1,6 +1,7 @@ package eu.kanade.tachiyomi.network import com.squareup.duktape.Duktape +import okhttp3.CacheControl import okhttp3.HttpUrl import okhttp3.Interceptor import okhttp3.Request @@ -21,7 +22,7 @@ class CloudflareInterceptor : Interceptor { val response = chain.proceed(chain.request()) // Check if Cloudflare anti-bot is on - if (response.code() == 503 && serverCheck.contains(response.header("Server"))) { + if (response.code() == 503 && response.header("Server") in serverCheck) { return chain.proceed(resolveChallenge(response)) } @@ -43,7 +44,7 @@ class CloudflareInterceptor : Interceptor { val pass = passPattern.find(content)?.groups?.get(1)?.value if (operation == null || challenge == null || pass == null) { - throw RuntimeException("Failed resolving Cloudflare challenge") + throw Exception("Failed resolving Cloudflare challenge") } val js = operation @@ -52,7 +53,7 @@ class CloudflareInterceptor : Interceptor { .replace("t.length", "${domain.length}") .replace("\n", "") - val result = (duktape.evaluate(js) as Double) + val result = duktape.evaluate(js) as Double val cloudflareUrl = HttpUrl.parse("${url.scheme()}://$domain/cdn-cgi/l/chk_jschl")!! .newBuilder() @@ -66,7 +67,7 @@ class CloudflareInterceptor : Interceptor { .add("Referer", url.toString()) .build() - return GET(cloudflareUrl, cloudflareHeaders) + return GET(cloudflareUrl, cloudflareHeaders, cache = CacheControl.Builder().build()) } }