Remove stetho dependency in OSS react native's NetworkingModule

Reviewed By: astreet

Differential Revision: D3038280

fb-gh-sync-id: 169e21b9276f928b7144ebf2f3b8487b5e87c073
shipit-source-id: 169e21b9276f928b7144ebf2f3b8487b5e87c073
This commit is contained in:
Saurabh Aggarwal 2016-03-23 12:40:39 -07:00 committed by Facebook Github Bot 3
parent 8cd3a38fd4
commit 3c488afb0f
4 changed files with 55 additions and 10 deletions

View File

@ -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'

View File

@ -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',

View File

@ -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();
}

View File

@ -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<NetworkInterceptorCreator> 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<NetworkInterceptorCreator> 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