From 9920ff617b01359538ea0fe21098d247c6dc267d Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 22 Aug 2020 12:49:00 -0400 Subject: [PATCH] Clean up X-Requested-With change This only really affects the initial request, subsequent requests may still use the package name. --- .../eu/kanade/tachiyomi/network/CloudflareInterceptor.kt | 3 ++- .../eu/kanade/tachiyomi/ui/webview/WebViewActivity.kt | 9 ++++----- .../java/eu/kanade/tachiyomi/util/system/WebViewUtil.kt | 2 ++ 3 files changed, 8 insertions(+), 6 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 d517a9e4c8..5b2cccde2c 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 ea94582d1d..89b7933f9b 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 b92866e463..8527c65394 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 {