Ez refactor in NetworkingModule (#38970)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/38970

Ez refactor in NetworkingModule to remove to lint warns

changelog: [internal] internal

Reviewed By: arushikesarwani94

Differential Revision: D48275729

fbshipit-source-id: a0fb66ebeeee1b8360bd6ab3d3be6c8626f2faab
This commit is contained in:
David Vacca authored and Facebook GitHub Bot committed 2023-08-15 12:26:12 -07:00
1 parent 540c41be91
commit 3b43d56f38
1 file changed
+25 -30
@@ -36,7 +36,6 @@ import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.CookieJar;
import okhttp3.Headers;
import okhttp3.Interceptor;
import okhttp3.JavaNetCookieJar;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
@@ -174,7 +173,7 @@ public final class NetworkingModule extends NativeNetworkingAndroidSpec {
* https://github.com/facebook/react-native/pull/37798#pullrequestreview-1518338914
*/
@Deprecated
public static interface CustomClientBuilder
public interface CustomClientBuilder
extends com.facebook.react.modules.network.CustomClientBuilder {}
private static void applyCustomBuilder(OkHttpClient.Builder builder) {
@@ -311,36 +310,32 @@ public final class NetworkingModule extends NativeNetworkingAndroidSpec {
// response and counts bytes received.
if (useIncrementalUpdates) {
clientBuilder.addNetworkInterceptor(
new Interceptor() {
@Override
public Response intercept(Interceptor.Chain chain) throws IOException {
Response originalResponse = chain.proceed(chain.request());
ProgressResponseBody responseBody =
new ProgressResponseBody(
originalResponse.body(),
new ProgressListener() {
long last = System.nanoTime();
chain -> {
Response originalResponse = chain.proceed(chain.request());
ProgressResponseBody responseBody =
new ProgressResponseBody(
originalResponse.body(),
new ProgressListener() {
long last = System.nanoTime();
@Override
public void onProgress(
long bytesWritten, long contentLength, boolean done) {
long now = System.nanoTime();
if (!done && !shouldDispatch(now, last)) {
return;
}
if (responseType.equals("text")) {
// For 'text' responses we continuously send response data with progress
// info to
// JS below, so no need to do anything here.
return;
}
ResponseUtil.onDataReceivedProgress(
reactApplicationContext, requestId, bytesWritten, contentLength);
last = now;
@Override
public void onProgress(long bytesWritten, long contentLength, boolean done) {
long now = System.nanoTime();
if (!done && !shouldDispatch(now, last)) {
return;
}
});
return originalResponse.newBuilder().body(responseBody).build();
}
if (responseType.equals("text")) {
// For 'text' responses we continuously send response data with progress
// info to
// JS below, so no need to do anything here.
return;
}
ResponseUtil.onDataReceivedProgress(
reactApplicationContext, requestId, bytesWritten, contentLength);
last = now;
}
});
return originalResponse.newBuilder().body(responseBody).build();
});
}