diff --git a/core/src/main/java/eu/kanade/tachiyomi/network/interceptor/CloudflareInterceptor.kt b/core/src/main/java/eu/kanade/tachiyomi/network/interceptor/CloudflareInterceptor.kt index 3490bf1e4..d8914b23a 100644 --- a/core/src/main/java/eu/kanade/tachiyomi/network/interceptor/CloudflareInterceptor.kt +++ b/core/src/main/java/eu/kanade/tachiyomi/network/interceptor/CloudflareInterceptor.kt @@ -18,7 +18,6 @@ import okhttp3.Response import uy.kohesive.injekt.injectLazy import java.io.IOException import java.util.concurrent.CountDownLatch -import java.util.concurrent.TimeUnit class CloudflareInterceptor(private val context: Context) : WebViewInterceptor(context) { @@ -109,9 +108,7 @@ class CloudflareInterceptor(private val context: Context) : WebViewInterceptor(c webview?.loadUrl(origRequestUrl, headers) } - // Wait a reasonable amount of time to retrieve the solution. The minimum should be - // around 4 seconds but it can take more due to slow networks or server issues. - latch.await(12, TimeUnit.SECONDS) + latch.awaitFor30Seconds() executor.execute { if (!cloudflareBypassed) { diff --git a/core/src/main/java/eu/kanade/tachiyomi/network/interceptor/Http103Interceptor.kt b/core/src/main/java/eu/kanade/tachiyomi/network/interceptor/Http103Interceptor.kt index 98f4a6b51..4d71705fc 100644 --- a/core/src/main/java/eu/kanade/tachiyomi/network/interceptor/Http103Interceptor.kt +++ b/core/src/main/java/eu/kanade/tachiyomi/network/interceptor/Http103Interceptor.kt @@ -15,7 +15,6 @@ import okhttp3.Response import okhttp3.ResponseBody.Companion.toResponseBody import java.io.IOException import java.util.concurrent.CountDownLatch -import java.util.concurrent.TimeUnit // TODO: Remove when OkHttp can handle HTTP 103 responses class Http103Interceptor(context: Context) : WebViewInterceptor(context) { @@ -76,7 +75,7 @@ class Http103Interceptor(context: Context) : WebViewInterceptor(context) { webview?.loadUrl(requestUrl, headers) } - latch.await(10, TimeUnit.SECONDS) + latch.awaitFor30Seconds() executor.execute { webview?.run { diff --git a/core/src/main/java/eu/kanade/tachiyomi/network/interceptor/WebViewInterceptor.kt b/core/src/main/java/eu/kanade/tachiyomi/network/interceptor/WebViewInterceptor.kt index 5247e9f71..45e70efbe 100644 --- a/core/src/main/java/eu/kanade/tachiyomi/network/interceptor/WebViewInterceptor.kt +++ b/core/src/main/java/eu/kanade/tachiyomi/network/interceptor/WebViewInterceptor.kt @@ -18,6 +18,8 @@ import okhttp3.Request import okhttp3.Response import uy.kohesive.injekt.injectLazy import java.util.Locale +import java.util.concurrent.CountDownLatch +import java.util.concurrent.TimeUnit abstract class WebViewInterceptor(private val context: Context) : Interceptor { @@ -71,6 +73,10 @@ abstract class WebViewInterceptor(private val context: Context) : Interceptor { .mapValues { it.value.getOrNull(0).orEmpty() } } + fun CountDownLatch.awaitFor30Seconds() { + await(30, TimeUnit.SECONDS) + } + fun createWebView(request: Request): WebView { return WebView(context).apply { setDefaultSettings()