mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-07 03:07:25 +01:00
Increase timeout duration of WebViewInterceptors (#8099)
This commit is contained in:
parent
56722140c9
commit
e2ce3f68bf
@ -18,7 +18,6 @@ import okhttp3.Response
|
|||||||
import uy.kohesive.injekt.injectLazy
|
import uy.kohesive.injekt.injectLazy
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.util.concurrent.CountDownLatch
|
import java.util.concurrent.CountDownLatch
|
||||||
import java.util.concurrent.TimeUnit
|
|
||||||
|
|
||||||
class CloudflareInterceptor(private val context: Context) : WebViewInterceptor(context) {
|
class CloudflareInterceptor(private val context: Context) : WebViewInterceptor(context) {
|
||||||
|
|
||||||
@ -109,9 +108,7 @@ class CloudflareInterceptor(private val context: Context) : WebViewInterceptor(c
|
|||||||
webview?.loadUrl(origRequestUrl, headers)
|
webview?.loadUrl(origRequestUrl, headers)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait a reasonable amount of time to retrieve the solution. The minimum should be
|
latch.awaitFor30Seconds()
|
||||||
// around 4 seconds but it can take more due to slow networks or server issues.
|
|
||||||
latch.await(12, TimeUnit.SECONDS)
|
|
||||||
|
|
||||||
executor.execute {
|
executor.execute {
|
||||||
if (!cloudflareBypassed) {
|
if (!cloudflareBypassed) {
|
||||||
|
@ -15,7 +15,6 @@ import okhttp3.Response
|
|||||||
import okhttp3.ResponseBody.Companion.toResponseBody
|
import okhttp3.ResponseBody.Companion.toResponseBody
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.util.concurrent.CountDownLatch
|
import java.util.concurrent.CountDownLatch
|
||||||
import java.util.concurrent.TimeUnit
|
|
||||||
|
|
||||||
// TODO: Remove when OkHttp can handle HTTP 103 responses
|
// TODO: Remove when OkHttp can handle HTTP 103 responses
|
||||||
class Http103Interceptor(context: Context) : WebViewInterceptor(context) {
|
class Http103Interceptor(context: Context) : WebViewInterceptor(context) {
|
||||||
@ -76,7 +75,7 @@ class Http103Interceptor(context: Context) : WebViewInterceptor(context) {
|
|||||||
webview?.loadUrl(requestUrl, headers)
|
webview?.loadUrl(requestUrl, headers)
|
||||||
}
|
}
|
||||||
|
|
||||||
latch.await(10, TimeUnit.SECONDS)
|
latch.awaitFor30Seconds()
|
||||||
|
|
||||||
executor.execute {
|
executor.execute {
|
||||||
webview?.run {
|
webview?.run {
|
||||||
|
@ -18,6 +18,8 @@ import okhttp3.Request
|
|||||||
import okhttp3.Response
|
import okhttp3.Response
|
||||||
import uy.kohesive.injekt.injectLazy
|
import uy.kohesive.injekt.injectLazy
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
|
import java.util.concurrent.CountDownLatch
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
abstract class WebViewInterceptor(private val context: Context) : Interceptor {
|
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() }
|
.mapValues { it.value.getOrNull(0).orEmpty() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun CountDownLatch.awaitFor30Seconds() {
|
||||||
|
await(30, TimeUnit.SECONDS)
|
||||||
|
}
|
||||||
|
|
||||||
fun createWebView(request: Request): WebView {
|
fun createWebView(request: Request): WebView {
|
||||||
return WebView(context).apply {
|
return WebView(context).apply {
|
||||||
setDefaultSettings()
|
setDefaultSettings()
|
||||||
|
Loading…
Reference in New Issue
Block a user