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:
parent
a7e9138593
commit
7e507abf32
@ -16,6 +16,7 @@ dependencies {
|
||||
|
||||
testImplementation 'junit:junit:4.13.2'
|
||||
testImplementation 'org.robolectric:robolectric:4.7.3'
|
||||
debugImplementation 'com.facebook.stetho:stetho-okhttp3:1.5.1'
|
||||
}
|
||||
|
||||
android {
|
||||
|
@ -0,0 +1,9 @@
|
||||
package com.owncloud.android.lib.common.http
|
||||
|
||||
import com.facebook.stetho.okhttp3.StethoInterceptor
|
||||
|
||||
class DebugInterceptorFactory {
|
||||
companion object {
|
||||
fun getInterceptor() = StethoInterceptor()
|
||||
}
|
||||
}
|
@ -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())
|
||||
}
|
||||
}
|
@ -58,6 +58,7 @@ public class HttpClient {
|
||||
private static Context sContext;
|
||||
private static HashMap<String, List<Cookie>> sCookieStore = new HashMap<>();
|
||||
private static LogInterceptor sLogInterceptor;
|
||||
private static DebugInterceptor sDebugInterceptor;
|
||||
|
||||
public static OkHttpClient getOkHttpClient() {
|
||||
if (sOkHttpClient == null) {
|
||||
@ -111,6 +112,7 @@ public class HttpClient {
|
||||
CookieJar cookieJar) {
|
||||
return new OkHttpClient.Builder()
|
||||
.addNetworkInterceptor(getLogInterceptor())
|
||||
.addNetworkInterceptor(DebugInterceptorFactory.Companion.getInterceptor())
|
||||
.protocols(Collections.singletonList(Protocol.HTTP_1_1))
|
||||
.readTimeout(HttpConstants.DEFAULT_DATA_TIMEOUT, TimeUnit.MILLISECONDS)
|
||||
.writeTimeout(HttpConstants.DEFAULT_DATA_TIMEOUT, TimeUnit.MILLISECONDS)
|
||||
@ -129,6 +131,13 @@ public class HttpClient {
|
||||
return sLogInterceptor;
|
||||
}
|
||||
|
||||
public static DebugInterceptor getDebugInterceptor() {
|
||||
if (sDebugInterceptor == null) {
|
||||
sDebugInterceptor = new DebugInterceptor();
|
||||
}
|
||||
return sDebugInterceptor;
|
||||
}
|
||||
|
||||
public static List<Cookie> getCookiesFromUrl(HttpUrl httpUrl) {
|
||||
return sCookieStore.get(httpUrl.host());
|
||||
}
|
||||
|
@ -0,0 +1,7 @@
|
||||
package com.owncloud.android.lib.common.http
|
||||
|
||||
class DebugInterceptorFactory {
|
||||
companion object {
|
||||
fun getInterceptor() = DummyInterceptor()
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user