Skip to content

Commit d2dd7e9

Browse files
committed
networking: Initialize NetworkingModule with proper OkHttpClient.
`getOkHttpClient` calls `createClient` if `OkHttpClientProvider` has no sClient (the root client) yet. Otherwise, it returns the root client. Thus, it has basically the same effect as `createClient` in this case, since only one NetworkingModule is ever instantiated and sharing its client with the very few other instances where OkHttpClientProvider is used shouldn't be a problem. We need this change so that OkHttpClientProvider gets an initialized sClient (`createClient` doesn't initialize the sClient, it just returns a new client). This will be necessary in the next commit, which fixes a networking bug.
1 parent 370bcff commit d2dd7e9

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

ReactAndroid/src/main/java/com/facebook/react/modules/network/NetworkingModule.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public interface ResponseHandler {
161161
* @param context the ReactContext of the application
162162
*/
163163
public NetworkingModule(final ReactApplicationContext context) {
164-
this(context, null, OkHttpClientProvider.createClient(), null);
164+
this(context, null, OkHttpClientProvider.getOkHttpClient(), null);
165165
}
166166

167167
/**
@@ -172,7 +172,7 @@ public NetworkingModule(final ReactApplicationContext context) {
172172
public NetworkingModule(
173173
ReactApplicationContext context,
174174
List<NetworkInterceptorCreator> networkInterceptorCreators) {
175-
this(context, null, OkHttpClientProvider.createClient(), networkInterceptorCreators);
175+
this(context, null, OkHttpClientProvider.getOkHttpClient(), networkInterceptorCreators);
176176
}
177177

178178
/**
@@ -181,7 +181,7 @@ public NetworkingModule(
181181
* caller does not provide one explicitly
182182
*/
183183
public NetworkingModule(ReactApplicationContext context, String defaultUserAgent) {
184-
this(context, defaultUserAgent, OkHttpClientProvider.createClient(), null);
184+
this(context, defaultUserAgent, OkHttpClientProvider.getOkHttpClient(), null);
185185
}
186186

187187
@Override
@@ -277,7 +277,6 @@ public void sendRequest(
277277
}
278278

279279
OkHttpClient.Builder clientBuilder = mClient.newBuilder();
280-
281280
if (!withCredentials) {
282281
clientBuilder.cookieJar(CookieJar.NO_COOKIES);
283282
}

0 commit comments

Comments
 (0)