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 d517a9e4c..5b2cccde2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/network/CloudflareInterceptor.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/network/CloudflareInterceptor.kt @@ -89,7 +89,8 @@ class CloudflareInterceptor(private val context: Context) : Interceptor { var isWebViewOutdated = false val origRequestUrl = request.url.toString() - val headers = request.headers.toMultimap().mapValues { it.value.getOrNull(0) ?: "" } + val headers = request.headers.toMultimap().mapValues { it.value.getOrNull(0) ?: "" }.toMutableMap() + headers["X-Requested-With"] = WebViewUtil.REQUESTED_WITH handler.post { val webview = WebView(context) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/webview/WebViewActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/webview/WebViewActivity.kt index ea94582d1..89b7933f9 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/webview/WebViewActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/webview/WebViewActivity.kt @@ -70,13 +70,14 @@ class WebViewActivity : BaseActivity() { if (bundle == null) { val url = intent.extras!!.getString(URL_KEY) ?: return - var headers = emptyMap() + var headers = mutableMapOf() val source = sourceManager.get(intent.extras!!.getLong(SOURCE_KEY)) as? HttpSource if (source != null) { - headers = source.headers.toMultimap().mapValues { it.value.getOrNull(0) ?: "" } + headers = source.headers.toMultimap().mapValues { it.value.getOrNull(0) ?: "" }.toMutableMap() binding.webview.settings.userAgentString = source.headers["User-Agent"] } + headers["X-Requested-With"] = WebViewUtil.REQUESTED_WITH binding.webview.setDefaultSettings() @@ -100,9 +101,7 @@ class WebViewActivity : BaseActivity() { binding.webview.webViewClient = object : WebViewClientCompat() { override fun shouldOverrideUrlCompat(view: WebView, url: String): Boolean { - val android_browser: MutableMap = HashMap() - android_browser["X-Requested-With"] = "com.android.browser" - view.loadUrl(url,android_browser) + view.loadUrl(url, headers) return true } diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/system/WebViewUtil.kt b/app/src/main/java/eu/kanade/tachiyomi/util/system/WebViewUtil.kt index b92866e46..8527c6539 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/system/WebViewUtil.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/system/WebViewUtil.kt @@ -11,6 +11,8 @@ object WebViewUtil { Regex(""".*Chrome/(\d+)\..*""") } + const val REQUESTED_WITH = "com.android.browser" + const val MINIMUM_WEBVIEW_VERSION = 80 fun supportsWebView(context: Context): Boolean {