From e2ce3f68bf2446682ebbe1438f413369d620c8bf Mon Sep 17 00:00:00 2001 From: AntsyLich <59261191+AntsyLich@users.noreply.github.com> Date: Wed, 28 Sep 2022 03:43:46 +0600 Subject: [PATCH] Increase timeout duration of WebViewInterceptors (#8099) --- .../tachiyomi/network/interceptor/CloudflareInterceptor.kt | 5 +---- .../tachiyomi/network/interceptor/Http103Interceptor.kt | 3 +-- .../tachiyomi/network/interceptor/WebViewInterceptor.kt | 6 ++++++ 3 files changed, 8 insertions(+), 6 deletions(-) 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 3490bf1e46..d8914b23a2 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 98f4a6b51f..4d71705fcb 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 5247e9f71d..45e70efbea 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()