diff --git a/app/src/main/java/eu/kanade/tachiyomi/network/NetworkHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/network/NetworkHelper.kt index 531496383b..ef9855a8df 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/network/NetworkHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/network/NetworkHelper.kt @@ -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(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) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/network/interceptor/IgnoreGzipInterceptor.kt b/app/src/main/java/eu/kanade/tachiyomi/network/interceptor/IgnoreGzipInterceptor.kt new file mode 100644 index 0000000000..f1331a5766 --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/network/interceptor/IgnoreGzipInterceptor.kt @@ -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) + } +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/network/interceptor/UncaughtExceptionInterceptor.kt b/app/src/main/java/eu/kanade/tachiyomi/network/interceptor/UncaughtExceptionInterceptor.kt index dccfd469d6..44fa9a5c1e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/network/interceptor/UncaughtExceptionInterceptor.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/network/interceptor/UncaughtExceptionInterceptor.kt @@ -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 {