Skip to content

Commit 3b43d56

Browse files
mdvaccafacebook-github-bot
authored andcommitted
Ez refactor in NetworkingModule (#38970)
Summary: Pull Request resolved: #38970 Ez refactor in NetworkingModule to remove to lint warns changelog: [internal] internal Reviewed By: arushikesarwani94 Differential Revision: D48275729 fbshipit-source-id: a0fb66ebeeee1b8360bd6ab3d3be6c8626f2faab
1 parent 540c41b commit 3b43d56

File tree

1 file changed

+26
-31
lines changed

1 file changed

+26
-31
lines changed

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

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import okhttp3.Callback;
3737
import okhttp3.CookieJar;
3838
import okhttp3.Headers;
39-
import okhttp3.Interceptor;
4039
import okhttp3.JavaNetCookieJar;
4140
import okhttp3.MediaType;
4241
import okhttp3.MultipartBody;
@@ -174,7 +173,7 @@ public static void setCustomClientBuilder(
174173
* https://github.com/facebook/react-native/pull/37798#pullrequestreview-1518338914
175174
*/
176175
@Deprecated
177-
public static interface CustomClientBuilder
176+
public interface CustomClientBuilder
178177
extends com.facebook.react.modules.network.CustomClientBuilder {}
179178

180179
private static void applyCustomBuilder(OkHttpClient.Builder builder) {
@@ -311,36 +310,32 @@ public void sendRequestInternal(
311310
// response and counts bytes received.
312311
if (useIncrementalUpdates) {
313312
clientBuilder.addNetworkInterceptor(
314-
new Interceptor() {
315-
@Override
316-
public Response intercept(Interceptor.Chain chain) throws IOException {
317-
Response originalResponse = chain.proceed(chain.request());
318-
ProgressResponseBody responseBody =
319-
new ProgressResponseBody(
320-
originalResponse.body(),
321-
new ProgressListener() {
322-
long last = System.nanoTime();
323-
324-
@Override
325-
public void onProgress(
326-
long bytesWritten, long contentLength, boolean done) {
327-
long now = System.nanoTime();
328-
if (!done && !shouldDispatch(now, last)) {
329-
return;
330-
}
331-
if (responseType.equals("text")) {
332-
// For 'text' responses we continuously send response data with progress
333-
// info to
334-
// JS below, so no need to do anything here.
335-
return;
336-
}
337-
ResponseUtil.onDataReceivedProgress(
338-
reactApplicationContext, requestId, bytesWritten, contentLength);
339-
last = now;
313+
chain -> {
314+
Response originalResponse = chain.proceed(chain.request());
315+
ProgressResponseBody responseBody =
316+
new ProgressResponseBody(
317+
originalResponse.body(),
318+
new ProgressListener() {
319+
long last = System.nanoTime();
320+
321+
@Override
322+
public void onProgress(long bytesWritten, long contentLength, boolean done) {
323+
long now = System.nanoTime();
324+
if (!done && !shouldDispatch(now, last)) {
325+
return;
340326
}
341-
});
342-
return originalResponse.newBuilder().body(responseBody).build();
343-
}
327+
if (responseType.equals("text")) {
328+
// For 'text' responses we continuously send response data with progress
329+
// info to
330+
// JS below, so no need to do anything here.
331+
return;
332+
}
333+
ResponseUtil.onDataReceivedProgress(
334+
reactApplicationContext, requestId, bytesWritten, contentLength);
335+
last = now;
336+
}
337+
});
338+
return originalResponse.newBuilder().body(responseBody).build();
344339
});
345340
}
346341

0 commit comments

Comments
 (0)