fix: some network stuff
This commit is contained in:
parent
5e38b00c1f
commit
945018653e
3 changed files with 37 additions and 4 deletions
|
@ -5,8 +5,10 @@ import android.os.Build
|
|||
import ani.dantotsu.Mapper
|
||||
import ani.dantotsu.settings.saving.PrefManager
|
||||
import ani.dantotsu.settings.saving.PrefName
|
||||
import ani.dantotsu.util.Logger
|
||||
import com.lagradost.nicehttp.Requests
|
||||
import eu.kanade.tachiyomi.network.interceptor.CloudflareInterceptor
|
||||
import eu.kanade.tachiyomi.network.interceptor.IgnoreGzipInterceptor
|
||||
import eu.kanade.tachiyomi.network.interceptor.UncaughtExceptionInterceptor
|
||||
import eu.kanade.tachiyomi.network.interceptor.UserAgentInterceptor
|
||||
import okhttp3.Cache
|
||||
|
@ -35,12 +37,21 @@ class NetworkHelper(
|
|||
),
|
||||
)
|
||||
.addInterceptor(UncaughtExceptionInterceptor())
|
||||
.addInterceptor(BrotliInterceptor)
|
||||
.addInterceptor(UserAgentInterceptor(::defaultUserAgentProvider))
|
||||
.addNetworkInterceptor(IgnoreGzipInterceptor())
|
||||
.addNetworkInterceptor(BrotliInterceptor)
|
||||
|
||||
class ConsoleLogger : HttpLoggingInterceptor.Logger {
|
||||
override fun log(message: String) {
|
||||
Logger.log("OkHttp: $message")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (PrefManager.getVal<Boolean>(PrefName.VerboseLogging)) {
|
||||
val httpLoggingInterceptor = HttpLoggingInterceptor(ConsoleLogger()).apply {
|
||||
level = HttpLoggingInterceptor.Level.BASIC
|
||||
|
||||
if (PrefManager.getVal(PrefName.VerboseLogging)) {
|
||||
val httpLoggingInterceptor = HttpLoggingInterceptor().apply {
|
||||
level = HttpLoggingInterceptor.Level.HEADERS
|
||||
}
|
||||
builder.addNetworkInterceptor(httpLoggingInterceptor)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
package eu.kanade.tachiyomi.network.interceptor
|
||||
|
||||
import okhttp3.Interceptor
|
||||
import okhttp3.Response
|
||||
|
||||
/**
|
||||
* To use [okhttp3.brotli.BrotliInterceptor] as a network interceptor,
|
||||
* add [IgnoreGzipInterceptor] right before it.
|
||||
*
|
||||
* This nullifies the transparent gzip of [okhttp3.internal.http.BridgeInterceptor]
|
||||
* so gzip and Brotli are explicitly handled by the [okhttp3.brotli.BrotliInterceptor].
|
||||
*/
|
||||
class IgnoreGzipInterceptor : Interceptor {
|
||||
override fun intercept(chain: Interceptor.Chain): Response {
|
||||
var request = chain.request()
|
||||
if (request.header("Accept-Encoding") == "gzip") {
|
||||
request = request.newBuilder().removeHeader("Accept-Encoding").build()
|
||||
}
|
||||
return chain.proceed(request)
|
||||
}
|
||||
}
|
|
@ -23,6 +23,7 @@ class UncaughtExceptionInterceptor : Interceptor {
|
|||
Logger.log(e)
|
||||
throw IOException("Request timed out") // there's some odd behavior throwing a SocketTimeoutException
|
||||
} catch (e: Exception) {
|
||||
Logger.log(e)
|
||||
if (e is IOException) {
|
||||
throw e
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue