Enable httpcache for cronet
This commit is contained in:
1 parent
9131f6f8cb
commit
2e23167e94
2 files changed
+5
-3
No files matched your search
@@ -5,6 +5,7 @@ import io.ktor.utils.io.pool.DirectByteBufferPool
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.suspendCancellableCoroutine
|
||||
import okio.Path.Companion.toOkioPath
|
||||
import org.chromium.net.CronetEngine
|
||||
import org.chromium.net.CronetException
|
||||
import org.chromium.net.UrlRequest
|
||||
@@ -18,10 +19,10 @@ import kotlin.coroutines.resumeWithException
|
||||
private val pool = DirectByteBufferPool(32)
|
||||
|
||||
val cronetHttpClient: CronetEngine = CronetEngine.Builder(appCtx).apply {
|
||||
enableHttp2(true)
|
||||
enableBrotli(true)
|
||||
enableHttpCache(CronetEngine.Builder.HTTP_CACHE_DISABLED, 0)
|
||||
enableQuic(true)
|
||||
val cache = (appCtx.cacheDir.toOkioPath() / "http_cache").toFile().apply { mkdirs() }
|
||||
setStoragePath(cache.absolutePath)
|
||||
enableHttpCache(CronetEngine.Builder.HTTP_CACHE_DISK_NO_HTTP, 100 * 1024)
|
||||
}.build()
|
||||
|
||||
val cronetHttpClientExecutor = EhApplication.nonCacheOkHttpClient.dispatcher.executorService
|
||||
|
||||
@@ -132,6 +132,7 @@ class SpiderDen(private val mGalleryInfo: GalleryInfo) {
|
||||
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
cronetRequest(url) {
|
||||
referer?.let { addHeader("Referer", it) }
|
||||
disableCache()
|
||||
}.execute { info ->
|
||||
val headers = info.allHeaders
|
||||
val type = headers["Content-Type"]?.first()?.toMediaType()?.subtype ?: "jpg"
|
||||
|
||||
Reference in new issue
Block a user