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