Fixes NetowrkingModule construction with interceptors

Reviewed By: andreicoman11

Differential Revision: D3316229

fbshipit-source-id: 0dc5cce68b6649ebd2ff44c313ab94a0f5a06f66
This commit is contained in:
Konstantin Raev 2016-05-18 04:55:50 -07:00 committed by Facebook Github Bot 2
parent 061151cdae
commit 921d0de2e8
1 changed files with 7 additions and 7 deletions

View File

@ -69,12 +69,16 @@ public final class NetworkingModule extends ReactContextBaseJavaModule {
OkHttpClient client,
@Nullable List<NetworkInterceptorCreator> networkInterceptorCreators) {
super(reactContext);
mClient = client;
if (networkInterceptorCreators != null) {
OkHttpClient.Builder clientBuilder = client.newBuilder();
for (NetworkInterceptorCreator networkInterceptorCreator : networkInterceptorCreators) {
mClient.networkInterceptors().add(networkInterceptorCreator.create());
clientBuilder.addNetworkInterceptor(networkInterceptorCreator.create());
}
client = clientBuilder.build();
}
mClient = client;
OkHttpClientProvider.replaceOkHttpClient(client);
mCookieHandler = new ForwardingCookieHandler(reactContext);
mCookieJarContainer = (CookieJarContainer) mClient.cookieJar();
mShuttingDown = false;
@ -87,7 +91,7 @@ public final class NetworkingModule extends ReactContextBaseJavaModule {
* caller does not provide one explicitly
* @param client the {@link OkHttpClient} to be used for networking
*/
public NetworkingModule(
/* package */ NetworkingModule(
ReactApplicationContext context,
@Nullable String defaultUserAgent,
OkHttpClient client) {
@ -121,10 +125,6 @@ public final class NetworkingModule extends ReactContextBaseJavaModule {
this(context, defaultUserAgent, OkHttpClientProvider.getOkHttpClient(), null);
}
public NetworkingModule(ReactApplicationContext reactContext, OkHttpClient client) {
this(reactContext, null, client, null);
}
@Override
public void initialize() {
mCookieJarContainer.setCookieJar(new JavaNetCookieJar(mCookieHandler));