From 921d0de2e8f572122651e1e239d4aa03f1fc1580 Mon Sep 17 00:00:00 2001 From: Konstantin Raev Date: Wed, 18 May 2016 04:55:50 -0700 Subject: [PATCH] Fixes NetowrkingModule construction with interceptors Reviewed By: andreicoman11 Differential Revision: D3316229 fbshipit-source-id: 0dc5cce68b6649ebd2ff44c313ab94a0f5a06f66 --- .../react/modules/network/NetworkingModule.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) 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 8a67aa104..93ab7f7b0 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 @@ -69,12 +69,16 @@ public final class NetworkingModule extends ReactContextBaseJavaModule { OkHttpClient client, @Nullable List 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));