From 3b4b1185e22d286d3986aad7f7def58b69b0c76e Mon Sep 17 00:00:00 2001 From: arkon Date: Tue, 23 Jun 2020 22:26:37 -0400 Subject: [PATCH] Add network header logging in debug builds --- .../kanade/tachiyomi/network/NetworkHelper.kt | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) 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 49455ef78..b61f8ccb1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/network/NetworkHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/network/NetworkHelper.kt @@ -1,10 +1,12 @@ package eu.kanade.tachiyomi.network import android.content.Context +import eu.kanade.tachiyomi.BuildConfig import java.io.File import java.util.concurrent.TimeUnit import okhttp3.Cache import okhttp3.OkHttpClient +import okhttp3.logging.HttpLoggingInterceptor class NetworkHelper(context: Context) { @@ -14,12 +16,22 @@ class NetworkHelper(context: Context) { val cookieManager = AndroidCookieJar() - val client = OkHttpClient.Builder() - .cookieJar(cookieManager) - .cache(Cache(cacheDir, cacheSize)) - .connectTimeout(30, TimeUnit.SECONDS) - .readTimeout(30, TimeUnit.SECONDS) - .build() + val client by lazy { + val builder = OkHttpClient.Builder() + .cookieJar(cookieManager) + .cache(Cache(cacheDir, cacheSize)) + .connectTimeout(30, TimeUnit.SECONDS) + .readTimeout(30, TimeUnit.SECONDS) + + if (BuildConfig.DEBUG) { + val httpLoggingInterceptor = HttpLoggingInterceptor().apply { + level = HttpLoggingInterceptor.Level.HEADERS + } + builder.addInterceptor(httpLoggingInterceptor) + } + + builder.build() + } val cloudflareClient = client.newBuilder() .addInterceptor(UserAgentInterceptor())