1
0
mirror of https://github.com/owncloud/android-library.git synced 2025-06-07 16:06:08 +00:00

add debug interceptor

This commit is contained in:
Christian Schabesberger 2021-10-04 11:08:24 +02:00 committed by Abel García de Prada
parent a7e9138593
commit 7e507abf32
5 changed files with 36 additions and 0 deletions

View File

@ -16,6 +16,7 @@ dependencies {
testImplementation 'junit:junit:4.13.2' testImplementation 'junit:junit:4.13.2'
testImplementation 'org.robolectric:robolectric:4.7.3' testImplementation 'org.robolectric:robolectric:4.7.3'
debugImplementation 'com.facebook.stetho:stetho-okhttp3:1.5.1'
} }
android { android {

View File

@ -0,0 +1,9 @@
package com.owncloud.android.lib.common.http
import com.facebook.stetho.okhttp3.StethoInterceptor
class DebugInterceptorFactory {
companion object {
fun getInterceptor() = StethoInterceptor()
}
}

View File

@ -0,0 +1,10 @@
package com.owncloud.android.lib.common.http
import okhttp3.Interceptor
import okhttp3.Response
class DummyInterceptor : Interceptor {
override fun intercept(chain: Interceptor.Chain): Response {
return chain.proceed(chain.request())
}
}

View File

@ -58,6 +58,7 @@ public class HttpClient {
private static Context sContext; private static Context sContext;
private static HashMap<String, List<Cookie>> sCookieStore = new HashMap<>(); private static HashMap<String, List<Cookie>> sCookieStore = new HashMap<>();
private static LogInterceptor sLogInterceptor; private static LogInterceptor sLogInterceptor;
private static DebugInterceptor sDebugInterceptor;
public static OkHttpClient getOkHttpClient() { public static OkHttpClient getOkHttpClient() {
if (sOkHttpClient == null) { if (sOkHttpClient == null) {
@ -111,6 +112,7 @@ public class HttpClient {
CookieJar cookieJar) { CookieJar cookieJar) {
return new OkHttpClient.Builder() return new OkHttpClient.Builder()
.addNetworkInterceptor(getLogInterceptor()) .addNetworkInterceptor(getLogInterceptor())
.addNetworkInterceptor(DebugInterceptorFactory.Companion.getInterceptor())
.protocols(Collections.singletonList(Protocol.HTTP_1_1)) .protocols(Collections.singletonList(Protocol.HTTP_1_1))
.readTimeout(HttpConstants.DEFAULT_DATA_TIMEOUT, TimeUnit.MILLISECONDS) .readTimeout(HttpConstants.DEFAULT_DATA_TIMEOUT, TimeUnit.MILLISECONDS)
.writeTimeout(HttpConstants.DEFAULT_DATA_TIMEOUT, TimeUnit.MILLISECONDS) .writeTimeout(HttpConstants.DEFAULT_DATA_TIMEOUT, TimeUnit.MILLISECONDS)
@ -129,6 +131,13 @@ public class HttpClient {
return sLogInterceptor; return sLogInterceptor;
} }
public static DebugInterceptor getDebugInterceptor() {
if (sDebugInterceptor == null) {
sDebugInterceptor = new DebugInterceptor();
}
return sDebugInterceptor;
}
public static List<Cookie> getCookiesFromUrl(HttpUrl httpUrl) { public static List<Cookie> getCookiesFromUrl(HttpUrl httpUrl) {
return sCookieStore.get(httpUrl.host()); return sCookieStore.get(httpUrl.host());
} }

View File

@ -0,0 +1,7 @@
package com.owncloud.android.lib.common.http
class DebugInterceptorFactory {
companion object {
fun getInterceptor() = DummyInterceptor()
}
}