Clean up X-Requested-With change

This only really affects the initial request, subsequent requests may still use the package name.
This commit is contained in:
arkon 2020-08-22 12:49:00 -04:00
parent 3f1355c413
commit 9920ff617b
3 changed files with 8 additions and 6 deletions

View File

@ -89,7 +89,8 @@ class CloudflareInterceptor(private val context: Context) : Interceptor {
var isWebViewOutdated = false var isWebViewOutdated = false
val origRequestUrl = request.url.toString() 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 { handler.post {
val webview = WebView(context) val webview = WebView(context)

View File

@ -70,13 +70,14 @@ class WebViewActivity : BaseActivity<WebviewActivityBinding>() {
if (bundle == null) { if (bundle == null) {
val url = intent.extras!!.getString(URL_KEY) ?: return val url = intent.extras!!.getString(URL_KEY) ?: return
var headers = emptyMap<String, String>()
var headers = mutableMapOf<String, String>()
val source = sourceManager.get(intent.extras!!.getLong(SOURCE_KEY)) as? HttpSource val source = sourceManager.get(intent.extras!!.getLong(SOURCE_KEY)) as? HttpSource
if (source != null) { 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"] binding.webview.settings.userAgentString = source.headers["User-Agent"]
} }
headers["X-Requested-With"] = WebViewUtil.REQUESTED_WITH
binding.webview.setDefaultSettings() binding.webview.setDefaultSettings()
@ -100,9 +101,7 @@ class WebViewActivity : BaseActivity<WebviewActivityBinding>() {
binding.webview.webViewClient = object : WebViewClientCompat() { binding.webview.webViewClient = object : WebViewClientCompat() {
override fun shouldOverrideUrlCompat(view: WebView, url: String): Boolean { override fun shouldOverrideUrlCompat(view: WebView, url: String): Boolean {
val android_browser: MutableMap<String, String> = HashMap() view.loadUrl(url, headers)
android_browser["X-Requested-With"] = "com.android.browser"
view.loadUrl(url,android_browser)
return true return true
} }

View File

@ -11,6 +11,8 @@ object WebViewUtil {
Regex(""".*Chrome/(\d+)\..*""") Regex(""".*Chrome/(\d+)\..*""")
} }
const val REQUESTED_WITH = "com.android.browser"
const val MINIMUM_WEBVIEW_VERSION = 80 const val MINIMUM_WEBVIEW_VERSION = 80
fun supportsWebView(context: Context): Boolean { fun supportsWebView(context: Context): Boolean {