Add interceptor to store cookies for cronet
This commit is contained in:
1 parent
15696f4e6e
commit
0b526040a3
4 files changed
+12
-1
No files matched your search
@@ -49,6 +49,7 @@ import eu.kanade.tachiyomi.util.lang.launchIO
|
||||
import eu.kanade.tachiyomi.util.lang.withUIContext
|
||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||
import okhttp3.AsyncDns
|
||||
import okhttp3.Cookie
|
||||
import okhttp3.android.AndroidAsyncDns
|
||||
import okio.Path.Companion.toOkioPath
|
||||
import splitties.arch.room.roomDb
|
||||
@@ -158,6 +159,13 @@ class EhApplication : Application(), ImageLoaderFactory {
|
||||
)
|
||||
|
||||
// TODO: Rewrite CronetInterceptor to use android.net.http.HttpEngine and make it Android 14 only when released
|
||||
addInterceptor { chain ->
|
||||
val request = chain.request()
|
||||
val response = chain.proceed(request)
|
||||
val url = request.url
|
||||
EhCookieStore.saveFromResponse(url, Cookie.parseAll(url, response.headers))
|
||||
response
|
||||
}
|
||||
addInterceptor(CronetInterceptor.newBuilder(cronetHttpClient).build())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,6 +60,7 @@ object EhCookieStore : CookieJar {
|
||||
fun copyNecessaryCookies() {
|
||||
val cookie = get(EhUrl.HOST_E.toHttpUrl()).filter { it.name == KEY_STAR || it.name == KEY_IPB_MEMBER_ID || it.name == KEY_IPB_PASS_HASH || it.name == KEY_IGNEOUS }
|
||||
cookie.forEach { manager.setCookie(EhUrl.HOST_EX, it.toString()) }
|
||||
flush()
|
||||
}
|
||||
|
||||
fun deleteCookie(url: HttpUrl, name: String) {
|
||||
@@ -90,7 +91,7 @@ object EhCookieStore : CookieJar {
|
||||
}
|
||||
|
||||
// See https://github.com/Ehviewer-Overhauled/Ehviewer/issues/873
|
||||
override fun saveFromResponse(url: HttpUrl, cookies: List<Cookie>) = cookies.filterNot { it.name == KEY_UTMP_NAME }.forEach { manager.setCookie(url.toString(), it.toString()) }
|
||||
override fun saveFromResponse(url: HttpUrl, cookies: List<Cookie>) = cookies.filterNot { it.name == KEY_UTMP_NAME }.forEach { manager.setCookie(url.toString(), it.toString()) }.also { flush() }
|
||||
|
||||
override fun loadForRequest(url: HttpUrl): List<Cookie> {
|
||||
val checkTips = EhUrl.DOMAIN_E in url.host
|
||||
|
||||
@@ -33,5 +33,6 @@ suspend fun migrateCookies() {
|
||||
database.cookiesDao().list().forEach {
|
||||
EhCookieStore.addCookie(it.toOkHttp3Cookie())
|
||||
}
|
||||
EhCookieStore.flush()
|
||||
}
|
||||
}
|
||||
@@ -80,6 +80,7 @@ fun UConfigScreen() {
|
||||
DisposableEffect(Unit) {
|
||||
onDispose {
|
||||
EhCookieStore.deleteCookie(EhUrl.host.toHttpUrl(), KEY_SETTINGS_PROFILE)
|
||||
EhCookieStore.flush()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user