diff --git a/Libraries/Network/RCTNetworking.android.js b/Libraries/Network/RCTNetworking.android.js index e6c879bc4e80ab..e8bee18a37a4a5 100644 --- a/Libraries/Network/RCTNetworking.android.js +++ b/Libraries/Network/RCTNetworking.android.js @@ -56,7 +56,8 @@ class RCTNetworking extends NativeEventEmitter { responseType: 'text' | 'base64', incrementalUpdates: boolean, timeout: number, - callback: (requestId: number) => any + callback: (requestId: number) => any, + withCredentials: boolean ) { const body = convertRequestBody(data); if (body && body.formData) { @@ -74,7 +75,8 @@ class RCTNetworking extends NativeEventEmitter { {...body, trackingName}, responseType, incrementalUpdates, - timeout + timeout, + withCredentials ); callback(requestId); } 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 d5396c1840a098..dce9dc31193f4d 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 @@ -36,6 +36,7 @@ import okhttp3.Call; import okhttp3.Callback; +import okhttp3.CookieJar; import okhttp3.Headers; import okhttp3.Interceptor; import okhttp3.JavaNetCookieJar; @@ -167,7 +168,8 @@ public void sendRequest( ReadableMap data, final String responseType, final boolean useIncrementalUpdates, - int timeout) { + int timeout, + boolean withCredentials) { Request.Builder requestBuilder = new Request.Builder().url(url); if (requestId != 0) { @@ -177,6 +179,10 @@ public void sendRequest( final RCTDeviceEventEmitter eventEmitter = getEventEmitter(executorToken); OkHttpClient.Builder clientBuilder = mClient.newBuilder(); + if (!withCredentials) { + clientBuilder.cookieJar(CookieJar.NO_COOKIES); + } + // If JS is listening for progress updates, install a ProgressResponseBody that intercepts the // response and counts bytes received. if (useIncrementalUpdates) { diff --git a/ReactAndroid/src/test/java/com/facebook/react/modules/network/NetworkingModuleTest.java b/ReactAndroid/src/test/java/com/facebook/react/modules/network/NetworkingModuleTest.java index 8849002c068e16..fc9b5adb926c05 100644 --- a/ReactAndroid/src/test/java/com/facebook/react/modules/network/NetworkingModuleTest.java +++ b/ReactAndroid/src/test/java/com/facebook/react/modules/network/NetworkingModuleTest.java @@ -100,7 +100,8 @@ public Object answer(InvocationOnMock invocation) throws Throwable { /* body */ null, /* responseType */ "text", /* useIncrementalUpdates*/ true, - /* timeout */ 0); + /* timeout */ 0, + /* withCredentials */ false); ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(Request.class); verify(httpClient).newCall(argumentCaptor.capture()); @@ -135,7 +136,8 @@ public void testFailGetWithInvalidHeadersStruct() throws Exception { /* body */ null, /* responseType */ "text", /* useIncrementalUpdates*/ true, - /* timeout */ 0); + /* timeout */ 0, + /* withCredentials */ false); verifyErrorEmit(emitter, 0); } @@ -166,7 +168,8 @@ public void testFailPostWithoutContentType() throws Exception { body, /* responseType */ "text", /* useIncrementalUpdates*/ true, - /* timeout */ 0); + /* timeout */ 0, + /* withCredentials */ false); verifyErrorEmit(emitter, 0); } @@ -227,7 +230,8 @@ public Object answer(InvocationOnMock invocation) throws Throwable { body, /* responseType */ "text", /* useIncrementalUpdates*/ true, - /* timeout */ 0); + /* timeout */ 0, + /* withCredentials */ false); ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(Request.class); verify(httpClient).newCall(argumentCaptor.capture()); @@ -270,7 +274,8 @@ public Object answer(InvocationOnMock invocation) throws Throwable { null, /* responseType */ "text", /* useIncrementalUpdates*/ true, - /* timeout */ 0); + /* timeout */ 0, + /* withCredentials */ false); ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(Request.class); verify(httpClient).newCall(argumentCaptor.capture()); Headers requestHeaders = argumentCaptor.getValue().headers(); @@ -324,7 +329,8 @@ public Object answer(InvocationOnMock invocation) throws Throwable { body, /* responseType */ "text", /* useIncrementalUpdates*/ true, - /* timeout */ 0); + /* timeout */ 0, + /* withCredentials */ false); // verify url, method, headers ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(Request.class); @@ -389,7 +395,8 @@ public Object answer(InvocationOnMock invocation) throws Throwable { body, /* responseType */ "text", /* useIncrementalUpdates*/ true, - /* timeout */ 0); + /* timeout */ 0, + /* withCredentials */ false); // verify url, method, headers ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(Request.class); @@ -492,7 +499,8 @@ public Object answer(InvocationOnMock invocation) throws Throwable { body, /* responseType */ "text", /* useIncrementalUpdates*/ true, - /* timeout */ 0); + /* timeout */ 0, + /* withCredentials */ false); // verify RequestBodyPart for image PowerMockito.verifyStatic(times(1)); @@ -556,7 +564,8 @@ public Object answer(InvocationOnMock invocation) throws Throwable { null, /* responseType */ "text", /* useIncrementalUpdates*/ true, - 0); + /* timeout */ 0, + /* withCredentials */ false); } verify(httpClient, times(3)).newCall(any(Request.class)); @@ -606,7 +615,8 @@ public Object answer(InvocationOnMock invocation) throws Throwable { null, /* responseType */ "text", /* useIncrementalUpdates*/ true, - 0); + /* timeout */ 0, + /* withCredentials */ false); } verify(httpClient, times(3)).newCall(any(Request.class));