Skip to content
This repository was archived by the owner on Mar 19, 2024. It is now read-only.

Commit 7e507ab

Browse files
theScrabiabelgardep
authored andcommitted
add debug interceptor
1 parent a7e9138 commit 7e507ab

File tree

5 files changed

+36
-0
lines changed

5 files changed

+36
-0
lines changed

owncloudComLibrary/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ dependencies {
1616

1717
testImplementation 'junit:junit:4.13.2'
1818
testImplementation 'org.robolectric:robolectric:4.7.3'
19+
debugImplementation 'com.facebook.stetho:stetho-okhttp3:1.5.1'
1920
}
2021

2122
android {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.owncloud.android.lib.common.http
2+
3+
import com.facebook.stetho.okhttp3.StethoInterceptor
4+
5+
class DebugInterceptorFactory {
6+
companion object {
7+
fun getInterceptor() = StethoInterceptor()
8+
}
9+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.owncloud.android.lib.common.http
2+
3+
import okhttp3.Interceptor
4+
import okhttp3.Response
5+
6+
class DummyInterceptor : Interceptor {
7+
override fun intercept(chain: Interceptor.Chain): Response {
8+
return chain.proceed(chain.request())
9+
}
10+
}

owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/HttpClient.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public class HttpClient {
5858
private static Context sContext;
5959
private static HashMap<String, List<Cookie>> sCookieStore = new HashMap<>();
6060
private static LogInterceptor sLogInterceptor;
61+
private static DebugInterceptor sDebugInterceptor;
6162

6263
public static OkHttpClient getOkHttpClient() {
6364
if (sOkHttpClient == null) {
@@ -111,6 +112,7 @@ private static OkHttpClient buildNewOkHttpClient(SSLSocketFactory sslSocketFacto
111112
CookieJar cookieJar) {
112113
return new OkHttpClient.Builder()
113114
.addNetworkInterceptor(getLogInterceptor())
115+
.addNetworkInterceptor(DebugInterceptorFactory.Companion.getInterceptor())
114116
.protocols(Collections.singletonList(Protocol.HTTP_1_1))
115117
.readTimeout(HttpConstants.DEFAULT_DATA_TIMEOUT, TimeUnit.MILLISECONDS)
116118
.writeTimeout(HttpConstants.DEFAULT_DATA_TIMEOUT, TimeUnit.MILLISECONDS)
@@ -129,6 +131,13 @@ public static LogInterceptor getLogInterceptor() {
129131
return sLogInterceptor;
130132
}
131133

134+
public static DebugInterceptor getDebugInterceptor() {
135+
if (sDebugInterceptor == null) {
136+
sDebugInterceptor = new DebugInterceptor();
137+
}
138+
return sDebugInterceptor;
139+
}
140+
132141
public static List<Cookie> getCookiesFromUrl(HttpUrl httpUrl) {
133142
return sCookieStore.get(httpUrl.host());
134143
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.owncloud.android.lib.common.http
2+
3+
class DebugInterceptorFactory {
4+
companion object {
5+
fun getInterceptor() = DummyInterceptor()
6+
}
7+
}

0 commit comments

Comments
 (0)