diff --git a/ReactAndroid/build.gradle b/ReactAndroid/build.gradle index 8663f0a28..022b15801 100644 --- a/ReactAndroid/build.gradle +++ b/ReactAndroid/build.gradle @@ -255,8 +255,6 @@ dependencies { compile 'com.android.support:recyclerview-v7:23.0.1' compile 'com.facebook.fresco:fresco:0.8.1' compile 'com.facebook.fresco:imagepipeline-okhttp:0.8.1' - compile 'com.facebook.stetho:stetho:1.2.0' - compile 'com.facebook.stetho:stetho-okhttp:1.2.0' compile 'com.fasterxml.jackson.core:jackson-core:2.2.3' compile 'com.google.code.findbugs:jsr305:3.0.0' compile 'com.squareup.okhttp:okhttp:2.5.0' diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/network/BUCK b/ReactAndroid/src/main/java/com/facebook/react/modules/network/BUCK index 254326d6a..42f9d30b0 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/network/BUCK +++ b/ReactAndroid/src/main/java/com/facebook/react/modules/network/BUCK @@ -13,8 +13,6 @@ android_library( react_native_dep('third-party/java/jsr-305:jsr-305'), react_native_dep('third-party/java/okhttp:okhttp'), react_native_dep('third-party/java/okio:okio'), - react_native_dep('third-party/java/stetho:stetho'), - react_native_dep('third-party/java/stetho:stetho-okhttp'), ], visibility = [ 'PUBLIC', diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/network/NetworkInterceptorCreator.java b/ReactAndroid/src/main/java/com/facebook/react/modules/network/NetworkInterceptorCreator.java new file mode 100644 index 000000000..b2b7ac250 --- /dev/null +++ b/ReactAndroid/src/main/java/com/facebook/react/modules/network/NetworkInterceptorCreator.java @@ -0,0 +1,20 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +package com.facebook.react.modules.network; + +import com.squareup.okhttp.Interceptor; + +/** + * Classes implementing this interface return a new {@link Interceptor} when the {@link #create} + * method is called. + */ +public interface NetworkInterceptorCreator { + Interceptor create(); +} diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/network/NetworkingModule.java b/ReactAndroid/src/main/java/com/facebook/react/modules/network/NetworkingModule.java index cd9e6b98c..066dbd0a4 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/network/NetworkingModule.java +++ b/ReactAndroid/src/main/java/com/facebook/react/modules/network/NetworkingModule.java @@ -15,6 +15,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.Reader; +import java.util.List; import java.util.concurrent.TimeUnit; import com.facebook.react.bridge.Arguments; @@ -28,7 +29,6 @@ import com.facebook.react.bridge.ReadableMap; import com.facebook.react.bridge.WritableArray; import com.facebook.react.bridge.WritableMap; import com.facebook.react.modules.core.DeviceEventManagerModule; -import com.facebook.stetho.okhttp.StethoInterceptor; import com.squareup.okhttp.Callback; import com.squareup.okhttp.Headers; @@ -67,20 +67,49 @@ public final class NetworkingModule extends ReactContextBaseJavaModule { /* package */ NetworkingModule( ReactApplicationContext reactContext, @Nullable String defaultUserAgent, - OkHttpClient client) { + OkHttpClient client, + @Nullable List networkInterceptorCreators) { super(reactContext); mClient = client; - mClient.networkInterceptors().add(new StethoInterceptor()); + if (networkInterceptorCreators != null) { + for (NetworkInterceptorCreator networkInterceptorCreator : networkInterceptorCreators) { + mClient.networkInterceptors().add(networkInterceptorCreator.create()); + } + } mCookieHandler = new ForwardingCookieHandler(reactContext); mShuttingDown = false; mDefaultUserAgent = defaultUserAgent; } + /** + * @param context the ReactContext of the application + * @param defaultUserAgent the User-Agent header that will be set for all requests where the + * caller does not provide one explicitly + * @param client the {@link OkHttpClient} to be used for networking + */ + public NetworkingModule( + ReactApplicationContext context, + @Nullable String defaultUserAgent, + OkHttpClient client) { + this(context, defaultUserAgent, client, null); + } + /** * @param context the ReactContext of the application */ public NetworkingModule(final ReactApplicationContext context) { - this(context, null, OkHttpClientProvider.getOkHttpClient()); + this(context, null, OkHttpClientProvider.getOkHttpClient(), null); + } + + /** + * @param context the ReactContext of the application + * @param networkInterceptorCreators list of {@link NetworkInterceptorCreator}'s whose create() + * methods would be called to attach the interceptors to the client. + */ + public NetworkingModule( + ReactApplicationContext context, + List networkInterceptorCreators) { + this(context, null, OkHttpClientProvider.getOkHttpClient(), networkInterceptorCreators); } /** @@ -89,11 +118,11 @@ public final class NetworkingModule extends ReactContextBaseJavaModule { * caller does not provide one explicitly */ public NetworkingModule(ReactApplicationContext context, String defaultUserAgent) { - this(context, defaultUserAgent, OkHttpClientProvider.getOkHttpClient()); + this(context, defaultUserAgent, OkHttpClientProvider.getOkHttpClient(), null); } public NetworkingModule(ReactApplicationContext reactContext, OkHttpClient client) { - this(reactContext, null, client); + this(reactContext, null, client, null); } @Override