Skip to content

Commit

Permalink
fix: some network stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
rebelonion committed May 24, 2024
1 parent 5e38b00 commit 9450186
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
19 changes: 15 additions & 4 deletions app/src/main/java/eu/kanade/tachiyomi/network/NetworkHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 9450186

Please sign in to comment.