#21 Fix cloudflare passing
This commit is contained in:
@@ -74,7 +74,7 @@ dependencies {
|
||||
implementation 'androidx.lifecycle:lifecycle-process:2.3.1'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
|
||||
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
|
||||
implementation 'androidx.recyclerview:recyclerview:1.2.0-rc01'
|
||||
implementation 'androidx.recyclerview:recyclerview:1.2.0'
|
||||
implementation 'androidx.viewpager2:viewpager2:1.1.0-alpha01'
|
||||
implementation 'androidx.preference:preference-ktx:1.1.1'
|
||||
implementation 'androidx.work:work-runtime-ktx:2.5.0'
|
||||
@@ -99,7 +99,7 @@ dependencies {
|
||||
implementation 'com.davemorrissey.labs:subsampling-scale-image-view-androidx:3.10.0'
|
||||
implementation 'com.github.solkin:disk-lru-cache:1.2'
|
||||
|
||||
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.6'
|
||||
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.7'
|
||||
|
||||
testImplementation 'junit:junit:4.13.2'
|
||||
testImplementation 'org.json:json:20201115'
|
||||
|
||||
@@ -3,18 +3,16 @@ package org.koitharu.kotatsu.browser.cloudflare
|
||||
import android.graphics.Bitmap
|
||||
import android.webkit.WebView
|
||||
import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||
import org.koitharu.kotatsu.core.network.AndroidCookieJar
|
||||
import org.koitharu.kotatsu.core.network.CookieJar
|
||||
import org.koitharu.kotatsu.core.network.WebViewClientCompat
|
||||
|
||||
class CloudFlareClient(
|
||||
private val cookieJar: AndroidCookieJar,
|
||||
private val cookieJar: CookieJar,
|
||||
private val callback: CloudFlareCallback,
|
||||
private val targetUrl: String
|
||||
) : WebViewClientCompat() {
|
||||
|
||||
init {
|
||||
cookieJar.remove(targetUrl, CF_UID, CF_CLEARANCE)
|
||||
}
|
||||
private val oldClearance = getCookieValue(CF_CLEARANCE)
|
||||
|
||||
override fun onPageStarted(view: WebView, url: String?, favicon: Bitmap?) {
|
||||
super.onPageStarted(view, url, favicon)
|
||||
@@ -32,16 +30,19 @@ class CloudFlareClient(
|
||||
}
|
||||
|
||||
private fun checkClearance() {
|
||||
val cookies = cookieJar.loadForRequest(targetUrl.toHttpUrl())
|
||||
if (cookies.any { it.name == CF_CLEARANCE }) {
|
||||
val clearance = getCookieValue(CF_CLEARANCE)
|
||||
if (clearance != null && clearance != oldClearance) {
|
||||
callback.onCheckPassed()
|
||||
}
|
||||
}
|
||||
|
||||
private fun getCookieValue(name: String): String? {
|
||||
return cookieJar.loadForRequest(targetUrl.toHttpUrl())
|
||||
.find { it.name == name }?.value
|
||||
}
|
||||
|
||||
private companion object {
|
||||
|
||||
const val CF_UID = "__cfduid"
|
||||
const val CF_CLEARANCE = "cf_clearance"
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ import okhttp3.HttpUrl
|
||||
import kotlin.coroutines.resume
|
||||
import kotlin.coroutines.suspendCoroutine
|
||||
|
||||
class AndroidCookieJar : CookieJar {
|
||||
class CookieJar : CookieJar {
|
||||
|
||||
private val cookieManager = CookieManager.getInstance()
|
||||
|
||||
@@ -28,15 +28,6 @@ class AndroidCookieJar : CookieJar {
|
||||
}
|
||||
}
|
||||
|
||||
fun remove(url: String, vararg names: String) {
|
||||
val cookies = cookieManager.getCookie(url) ?: return
|
||||
val newCookies = cookies.split(";")
|
||||
.filterNot { cookie ->
|
||||
names.any { cookie.startsWith("$it=") }
|
||||
}.joinToString(";")
|
||||
cookieManager.setCookie(url, newCookies)
|
||||
}
|
||||
|
||||
fun clearAsync() {
|
||||
cookieManager.removeAllCookies(null)
|
||||
}
|
||||
@@ -11,7 +11,7 @@ import java.util.concurrent.TimeUnit
|
||||
|
||||
val networkModule
|
||||
get() = module {
|
||||
single { AndroidCookieJar() } bind CookieJar::class
|
||||
single { CookieJar() } bind CookieJar::class
|
||||
single(named(CacheUtils.QUALIFIER_HTTP)) { CacheUtils.createHttpCache(androidContext()) }
|
||||
single {
|
||||
OkHttpClient.Builder().apply {
|
||||
|
||||
@@ -11,7 +11,7 @@ import org.koin.android.ext.android.get
|
||||
import org.koin.android.ext.android.inject
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.base.ui.BasePreferenceFragment
|
||||
import org.koitharu.kotatsu.core.network.AndroidCookieJar
|
||||
import org.koitharu.kotatsu.core.network.CookieJar
|
||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||
import org.koitharu.kotatsu.local.data.Cache
|
||||
import org.koitharu.kotatsu.search.ui.MangaSuggestionsProvider
|
||||
@@ -75,7 +75,7 @@ class HistorySettingsFragment : BasePreferenceFragment(R.string.history_and_cach
|
||||
}
|
||||
AppSettings.KEY_COOKIES_CLEAR -> {
|
||||
viewLifecycleScope.launch {
|
||||
val cookieJar = get<AndroidCookieJar>()
|
||||
val cookieJar = get<CookieJar>()
|
||||
cookieJar.clear()
|
||||
Snackbar.make(
|
||||
listView ?: return@launch,
|
||||
|
||||
Reference in New Issue
Block a user