Skip to content

Commit

Permalink
Ez refactor in NetworkingModule (#38970)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mdvacca authored and facebook-github-bot committed Aug 15, 2023
1 parent 540c41b commit 3b43d56
Showing 1 changed file with 26 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import okhttp3.Callback;
import okhttp3.CookieJar;
import okhttp3.Headers;
import okhttp3.Interceptor;
import okhttp3.JavaNetCookieJar;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
Expand Down Expand Up @@ -174,7 +173,7 @@ public static void setCustomClientBuilder(
* 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) {
Expand Down Expand Up @@ -311,36 +310,32 @@ public void sendRequestInternal(
// 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();

@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;
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;
}
});
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();
});
}

Expand Down

0 comments on commit 3b43d56

Please # to comment.